Skip to content

Commit 446df85

Browse files
committed
Update unregistration page
1 parent b1f3688 commit 446df85

File tree

7 files changed

+419
-28
lines changed

7 files changed

+419
-28
lines changed

docs/.vitepress/theme/preference/PreferenceSwitch.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ onMounted(() => {
321321
.tip .maven,
322322
.tip .paper,
323323
.tip .spigot {
324-
color: var(--vt-c-text-code);
324+
//color: var(--vt-c-text-code);
325325
/* transition: color 0.5s; */
326-
font-weight: 600;
326+
//font-weight: 600;
327327
}
328328
</style>

docs/en/create-commands/registration.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
order: 1
3+
preferences: ["paper-spigot"]
34
authors:
45
- DerEchtePilz
56
- willkroboth
@@ -202,11 +203,22 @@ Register the command with the provided plugin's name.
202203

203204
## Command loading order
204205

205-
It is recommended to register commands in either the `onLoad()` or `onEnable()` method. With the CommandAPI, depending on whether you use `onLoad()` or `onEnable()` to load your commands depends on whether your plugin is used with Minecraft's functions:
206+
Places where you can register commands are listed below:
206207

207-
| When to load | What to do |
208-
|---------------------|--------------------------------------------------------------------------------------------------------------------------------|
209-
| `onLoad()` method | Register commands to be used in Minecraft functions ([see the Function section for more info](./functions-and-tags/functions)) |
210-
| `onEnable()` method | Register regular commands |
208+
<div class="paper">
211209

212-
The CommandAPI does support registering commands outside of these methods while the server is running. Commands registered after the server is done loading _should_ work the same as commands registered in `onEnable`.
210+
| When to load | What to do |
211+
|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
212+
| `bootstrap(BootstrapContext)` method | Register commands to be used in Minecraft functions ([see the Function section for more info](./functions-and-tags/functions)) |
213+
| `onLoad()`/`onEnable()` method | Register regular commands not available in datapacks by default |
214+
215+
</div>
216+
<div class="spigot">
217+
218+
| When to load | What to do |
219+
|--------------------------------|-----------------------------------------------------------------|
220+
| `onLoad()`/`onEnable()` method | Register regular commands not available in datapacks by default |
221+
222+
</div>
223+
224+
The CommandAPI does support registering commands outside of these methods while the server is running. Commands registered after the server is done loading _should_ work the same as commands registered in `onLoad()`/`onEnable()`.

docs/en/create-commands/unregistration.md

Lines changed: 140 additions & 20 deletions
Large diffs are not rendered by default.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package createcommands;
2+
3+
import dev.jorel.commandapi.CommandAPI;
4+
import dev.jorel.commandapi.CommandAPIBukkit;
5+
import dev.jorel.commandapi.CommandAPICommand;
6+
import dev.jorel.commandapi.CommandAPIPaperConfig;
7+
import dev.jorel.commandapi.arguments.MultiLiteralArgument;
8+
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
9+
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
10+
import net.kyori.adventure.text.Component;
11+
import org.bukkit.plugin.java.JavaPlugin;
12+
import org.bukkit.scheduler.BukkitRunnable;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
class Unregistration {
16+
17+
// #region registerBootstrapExample
18+
public class MyPluginBootstrap implements PluginBootstrap {
19+
20+
@Override
21+
public void bootstrap(@NotNull BootstrapContext context) {
22+
CommandAPI.onLoad(new CommandAPIPaperConfig<>(context.getPluginMeta(), context));
23+
24+
new CommandAPICommand("inbootstrap")
25+
.executes((sender, args) -> {
26+
sender.sendMessage(Component.text("This command is registed in step 3!"));
27+
})
28+
.register();
29+
}
30+
}
31+
// #endregion registerBootstrapExample
32+
33+
{
34+
new JavaPlugin() {
35+
// #region unregisterBukkitExample
36+
@Override
37+
public void onLoad() {
38+
CommandAPIBukkit.unregister("version", true, true);
39+
}
40+
// #endregion unregisterBukkitExample
41+
};
42+
43+
new JavaPlugin() {
44+
// #region unregisterVanillaExample
45+
@Override
46+
public void onEnable() {
47+
CommandAPI.unregister("gamemode");
48+
}
49+
// #endregion unregisterVanillaExample
50+
};
51+
52+
new JavaPlugin() {
53+
// #region unregisterVanillaAndReplaceExample
54+
@Override
55+
public void onEnable() {
56+
// Register our new /gamemode, with survival, creative, adventure and spectator
57+
new CommandAPICommand("gamemode")
58+
.withArguments(new MultiLiteralArgument("gamemodes", "survival", "creative", "adventure", "spectator"))
59+
.executes((sender, args) -> {
60+
// Implementation of our /gamemode command
61+
})
62+
.register();
63+
}
64+
// #endregion unregisterVanillaAndReplaceExample
65+
};
66+
67+
new JavaPlugin() {
68+
// #region unregisterPluginExample
69+
@Override
70+
public void onEnable() {
71+
CommandAPIBukkit.unregister("luckperms:luckperms", false, true);
72+
}
73+
// #endregion unregisterPluginExample
74+
};
75+
76+
new JavaPlugin() {
77+
// #region unregisterCommandAPIExample
78+
@Override
79+
public void onEnable() {
80+
CommandAPI.unregister("break");
81+
}
82+
// #endregion unregisterCommandAPIExample
83+
};
84+
85+
new JavaPlugin() {
86+
// #region unregisterBukkitHelpExample
87+
@Override
88+
public void onEnable() {
89+
CommandAPIBukkit.unregister("help", false, true);
90+
}
91+
// #endregion unregisterBukkitHelpExample
92+
};
93+
94+
new JavaPlugin() {
95+
// #region unregisterVanillaNamespaceOnlyExample
96+
@Override
97+
public void onEnable() {
98+
new BukkitRunnable() {
99+
@Override
100+
public void run() {
101+
CommandAPI.unregister("minecraft:gamemode");
102+
}
103+
}.runTaskLater(this, 0);
104+
}
105+
// #endregion unregisterVanillaNamespaceOnlyExample
106+
};
107+
108+
new JavaPlugin() {
109+
// #region unregisterDelayedVanillaBadExample
110+
// NOT RECOMMENDED
111+
@Override
112+
public void onEnable() {
113+
new BukkitRunnable() {
114+
@Override
115+
public void run() {
116+
CommandAPI.unregister("gamemode");
117+
}
118+
}.runTaskLater(this, 0);
119+
}
120+
// #endregion unregisterDelayedVanillaBadExample
121+
};
122+
123+
new JavaPlugin() {
124+
// #region unregisterDelayedVanillaGoodExample
125+
@Override
126+
public void onEnable() {
127+
new BukkitRunnable() {
128+
@Override
129+
public void run() {
130+
CommandAPI.unregister("gamemode", true);
131+
}
132+
}.runTaskLater(this, 0);
133+
}
134+
// #endregion unregisterDelayedVanillaGoodExample
135+
};
136+
}
137+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package createcommands
2+
3+
import dev.jorel.commandapi.CommandAPI
4+
import dev.jorel.commandapi.CommandAPIBukkit
5+
import dev.jorel.commandapi.CommandAPICommand
6+
import dev.jorel.commandapi.CommandAPIPaperConfig
7+
import dev.jorel.commandapi.arguments.MultiLiteralArgument
8+
import dev.jorel.commandapi.executors.CommandExecutor
9+
import io.papermc.paper.plugin.bootstrap.BootstrapContext
10+
import io.papermc.paper.plugin.bootstrap.PluginBootstrap
11+
import net.kyori.adventure.text.Component
12+
import org.bukkit.plugin.java.JavaPlugin
13+
import org.bukkit.scheduler.BukkitRunnable
14+
15+
class UnregistrationKT {
16+
17+
// #region registerBootstrapExample
18+
class MyPluginBootstrap : PluginBootstrap {
19+
20+
override fun bootstrap(context: BootstrapContext) {
21+
CommandAPI.onLoad(CommandAPIPaperConfig(context.pluginMeta, context))
22+
23+
CommandAPICommand("inbootstrap")
24+
.executes(CommandExecutor { sender, _ ->
25+
sender.sendMessage(Component.text("This command is registed in step 3!"))
26+
})
27+
.register()
28+
}
29+
}
30+
// #endregion registerBootstrapExample
31+
32+
class A : JavaPlugin() {
33+
// #region unregisterBukkitExample
34+
override fun onLoad() {
35+
CommandAPIBukkit.unregister("version", true, true)
36+
}
37+
// #endregion unregisterBukkitExample
38+
}
39+
40+
class B : JavaPlugin() {
41+
// #region unregisterVanillaExample
42+
override fun onEnable() {
43+
CommandAPI.unregister("gamemode")
44+
}
45+
// #endregion unregisterVanillaExample
46+
}
47+
48+
class C : JavaPlugin() {
49+
// #region unregisterVanillaAndReplaceExample
50+
override fun onEnable() {
51+
// Register our new /gamemode, with survival, creative, adventure and spectator
52+
CommandAPICommand("gamemode")
53+
.withArguments(MultiLiteralArgument("gamemodes", "survival", "creative", "adventure", "spectator"))
54+
.executes(CommandExecutor { sender, args ->
55+
// Implementation of our /gamemode command
56+
})
57+
.register()
58+
}
59+
// #endregion unregisterVanillaAndReplaceExample
60+
}
61+
62+
class D : JavaPlugin() {
63+
// #region unregisterPluginExample
64+
override fun onEnable() {
65+
CommandAPIBukkit.unregister("luckperms:luckperms", false, true)
66+
}
67+
// #endregion unregisterPluginExample
68+
}
69+
70+
class E : JavaPlugin() {
71+
// #region unregisterCommandAPIExample
72+
override fun onEnable() {
73+
CommandAPI.unregister("break")
74+
}
75+
// #endregion unregisterCommandAPIExample
76+
}
77+
78+
class F : JavaPlugin() {
79+
// #region unregisterBukkitHelpExample
80+
override fun onEnable() {
81+
CommandAPIBukkit.unregister("help", false, true)
82+
}
83+
// #endregion unregisterBukkitHelpExample
84+
}
85+
86+
class G : JavaPlugin() {
87+
// #region unregisterVanillaNamespaceOnlyExample
88+
override fun onEnable() {
89+
object : BukkitRunnable() {
90+
override fun run() {
91+
CommandAPI.unregister("minecraft:gamemode")
92+
}
93+
}.runTaskLater(this, 0)
94+
}
95+
// #endregion unregisterVanillaNamespaceOnlyExample
96+
}
97+
98+
class H : JavaPlugin() {
99+
// #region unregisterDelayedVanillaBadExample
100+
// NOT RECOMMENDED
101+
override fun onEnable() {
102+
object : BukkitRunnable() {
103+
override fun run() {
104+
CommandAPI.unregister("gamemode")
105+
}
106+
}.runTaskLater(this, 0)
107+
}
108+
// #endregion unregisterDelayedVanillaBadExample
109+
}
110+
111+
class I : JavaPlugin() {
112+
// #region unregisterDelayedVanillaGoodExample
113+
override fun onEnable() {
114+
object : BukkitRunnable() {
115+
override fun run() {
116+
CommandAPI.unregister("gamemode", true)
117+
}
118+
}.runTaskLater(this, 0)
119+
}
120+
// #endregion unregisterDelayedVanillaGoodExample
121+
}
122+
}

0 commit comments

Comments
 (0)