You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/api/skript/addons.md
+99-2Lines changed: 99 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,8 @@ public class MyAddon {
51
51
```
52
52
53
53
## Addon modules
54
-
SkriptAddon instances can also be used to load [AddonModules](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/addon/AddonModule.java), which allow you to modularize (organize) the features you are registering. This makes it much easier to control which features of your addon are enabled and which are not.
54
+
SkriptAddon instances can also be used to load [AddonModules](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/addon/AddonModule.java), which allow you to modularize (organize) the features you are registering.
55
+
This makes it much easier to control which features of your addon are enabled and which are not.
55
56
56
57
### Creating an addon module
57
58
Addon modules are defined by implementing the AddonModule interface on a class.
@@ -70,18 +71,41 @@ This method is intended to be implemented by modules that register components th
70
71
The `load(SkriptAddon)` method is the second and final stage of module initialization.
71
72
This method is intended to be implemented by modules that register components that are generally only used within the module itself, such as [syntax](../../syntax).
72
73
74
+
#### name
75
+
The `name` method, which is required to be implemented, should just return a name that describes the module's purpose.
76
+
For example, if you were creating a module covering math syntax, you could call it `math`.
77
+
The module name can really be anything, though, as it does not affect functionality.
78
+
It is primarily used for documentation and logging purposes.
79
+
73
80
#### Example module
74
81
The following is a simple example of a module that prints a message when it loads:
75
82
```java
83
+
// MyModule.java
76
84
importorg.skriptlang.skript.addon.AddonModule;
77
85
publicclassMyModuleimplementsAddonModule {
78
86
@Override
87
+
publicvoidinit(SkriptAddonaddon) {
88
+
System.out.println("MyModule has just been initialized by "+ addon.name());
89
+
}
90
+
91
+
@Override
79
92
publicvoidload(SkriptAddonaddon) {
80
93
System.out.println("MyModule has just been loaded by "+ addon.name());
81
94
}
95
+
96
+
@Override
97
+
publicStringname() {
98
+
return"MyModule";
99
+
}
82
100
}
83
101
```
84
102
103
+
When `MyModule` is loaded, `init` is run before `load`, so the output will look something like:
104
+
```bash title="My Skript Process"
105
+
MyModule has just been initialized by ...
106
+
MyModule has just been loaded by ...
107
+
```
108
+
85
109
### Loading an addon module
86
110
Defined on SkriptAddon is a utility method, `loadModules(AddonModule...)` that loads method.
87
111
That is, it first calls `canLoad` on each provided module, compiling a collection of those that are permitted to load.
@@ -101,13 +125,86 @@ public class MyAddon {
101
125
}
102
126
}
103
127
```
128
+
### Hierarchical addon modules
129
+
We also provide an implementation of AddonModule, [HierarchicalAddonModule](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/addon/HierarchicalAddonModule.java), which allows defining a module with children (submodules).
130
+
This implementation overrides the standard module methods to manage loading the hierarchy.
131
+
Instead, implementors can override methods such as `canLoadSelf`, `initSelf` and `loadSelf` which function the same as their regular versions.
132
+
133
+
The key method of this implementation is `children`, which can be overridden.
134
+
The method should return an iterable of the instances of the children modules.
135
+
136
+
#### Example hierarchical modules
137
+
Here is an example of defining a module with a child module:
// We define a constructor for setting this module's parent
171
+
publicMyChildModule(AddonModuleparentModule) {
172
+
super(parentModule);
173
+
}
174
+
175
+
// MyChildModule has no children, so no need to override 'children'
176
+
177
+
@Override
178
+
publicvoidinitSelf(SkriptAddonaddon) {
179
+
System.out.println("MyChildModule has just been initialized by "+ addon.name());
180
+
}
181
+
182
+
@Override
183
+
publicvoidloadSelf(SkriptAddonaddon) {
184
+
System.out.println("MyChildModule has just been loaded by "+ addon.name());
185
+
}
186
+
187
+
@Override
188
+
publicStringname() {
189
+
return"MyChildModule";
190
+
}
191
+
}
192
+
```
193
+
194
+
When `MyParentModule` is loaded, its `...Self` methods will always run before the equivalent for its children, meaning the output will look something like:
195
+
```bash title="My Skript Process"
196
+
MyParentModule has just been initialized by ...
197
+
MyChildModule has just been initialized by ...
198
+
MyParentModule has just been loaded by ...
199
+
MyChildModule has just been loaded by ...
200
+
```
104
201
105
202
## Using registries
106
203
SkriptAddon instances provide access to Skript's registries through multiple methods defined on the interface.
107
204
108
205
:::note
109
206
This section does not cover any of the registries defined and used by the API.
110
-
For more information about what registries are available, please review the [registries](../../registries) section.
207
+
For more information about what registries are available, see the [registries](../../registries) section.
0 commit comments