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: docs/en/create-commands/functions-and-tags/functions.md
+35-5Lines changed: 35 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
---
2
2
order: 1
3
+
preferences: ["paper-spigot"]
3
4
authors:
4
5
- DerEchtePilz
5
6
- willkroboth
@@ -17,29 +18,58 @@ The CommandAPI has support to use Minecraft's [functions](https://minecraft.wiki
17
18
18
19
Minecraft 1.16+ changes the way that datapacks are loaded on the server, so that they load before plugins are enabled. This means that non-vanilla commands that are declared in functions and tags will be detected as invalid, causing the server to throw a lot of errors at the very start.
19
20
21
+
<divclass="paper">
22
+
23
+
To make commands available in datapacks, they have to be registered at the right place. More on that later.
24
+
25
+
</div>
26
+
<divclass="spigot">
27
+
20
28
The CommandAPI reloads datapacks once the server has finished loading using all declared commands, therefore **the error messages at the start of the server can be ignored**.
21
29
30
+
</div>
31
+
22
32
:::
23
33
24
34
## Using custom commands in functions
25
35
26
-
In order to use a command from your plugin in a `.mcfunction` file, you must register your command in your plugin's `onLoad()` method, instead of the `onEnable()` method. Failure to do so will not allow the command to be registered for Minecraft functions, causing the function file to fail to load during the server startup phase.
36
+
<divclass="paper">
37
+
38
+
In order to use a command from your plugin in a `.mcfunction` file, you must register your command in your plugin's `bootstrap(BootstrapContext)` method, instead of the `onLoad()`/`onEnable()` method. Failure to do so will not allow the command to be registered for Minecraft functions, causing the function file to fail to load during the server startup phase.
27
39
28
40
:::info
29
41
30
-
In short, if you want to register a command which can be used in Minecraft functions, register it in your plugin's `onLoad()` method.
42
+
In short, if you want to register a command which can be used in Minecraft functions, register it in your plugin's `bootstrap(BootstrapContext)` method.
31
43
32
44
:::
33
45
46
+
</div>
47
+
34
48
::::tip Example – Registering command for use in a function
35
49
36
-
Say we have a command `/killall` that simply kills all entities in all worlds on the server. If we were to register this in our `onLoad()` method, this would allow us to use the `/killall` command in Minecraft functions and tags.
50
+
<divclass="paper">
51
+
52
+
Say we have a command `/killall` that simply kills all entities in all worlds on the server. To make it available in a function, we want to register the command in the `bootstrap(BootstrapContext)` method.
Say we have a command `/killall` that simply kills all entities in all worlds on the server. It doesn't matter where we register to make the command available in a function, but we'll just use the `onLoad()` method here.
0 commit comments