Unregistering /help command ignores a new implementation for that command
FastJoe0 opened this issue · comments
CommandAPI version
9.1.0
Minecraft version
1.20.1
Are you shading the CommandAPI?
Yes
What I did
I unregistered bukkit /help command but my custom vanilla /help command doesn't work either (only works if /minecraft:help is used).
- Added this code to onEnable()
new BukkitRunnable() {
@Override
public void run() {
CommandAPIBukkit.unregister("help", true, true);
}
}.runTaskLater(this, 0);
new CommandHelp(this).registerHelpCommand(); //my own help command
What actually happened
When I type /help it shows Unknown command. Type "/help"
For some reason only /minecraft:help shows my implementation of this command
What should have happened
my /help command should be displayed.
Server logs and CommandAPI config
No response
Other
No response
I think this is the order of events that is happening here (should be consistent with the schedule in the docs here):
- Vanilla commands load, adding Vanilla
help
to the Vanilla CommandDispatcher - Your plugin enables
- Your unregister task is scheduled
- Your
help
command gets added to the Vanilla CommandDispatcher (fusing with the vanilla implementation)
- Bukkit
help
andbukkit:help
is added to the Bukkit CommandMap - Vanilla commands are moved from the CommandDispatcher to the CommandMap
help
already exists in the CommandMap, so your help command is only available asminecraft:help
- The server is done loading
- Your unregister task runs, removing
help
andbukkit:help
- Your unregister task runs, removing
So, since the Bukkit version of help
existed in the CommandMap when Vanilla commands were being transferred, your command is only accessible as minecraft:help
. When your unregister task is run, /help
still refers to the Bukkit version, so it is removed. In the end, only minecraft:help
is left over.
You should be able to fix this by adding your version of the help
command after Bukkit's help
is removed. That would look like this:
new BukkitRunnable() {
@Override
public void run() {
CommandAPIBukkit.unregister("help", true, true);
new CommandHelp(this).registerHelpCommand();
}
}.runTaskLater(this, 0);
I think this is the order of events that is happening here (should be consistent with the schedule in the docs here):
Vanilla commands load, adding Vanilla
help
to the Vanilla CommandDispatcherYour plugin enables
- Your unregister task is scheduled
- Your
help
command gets added to the Vanilla CommandDispatcher (fusing with the vanilla implementation)Bukkit
help
andbukkit:help
is added to the Bukkit CommandMapVanilla commands are moved from the CommandDispatcher to the CommandMap
help
already exists in the CommandMap, so your help command is only available asminecraft:help
The server is done loading
- Your unregister task runs, removing
help
andbukkit:help
So, since the Bukkit version of
help
existed in the CommandMap when Vanilla commands were being transferred, your command is only accessible asminecraft:help
. When your unregister task is run,/help
still refers to the Bukkit version, so it is removed. In the end, onlyminecraft:help
is left over.You should be able to fix this by adding your version of the
help
command after Bukkit'shelp
is removed. That would look like this:new BukkitRunnable() { @Override public void run() { CommandAPIBukkit.unregister("help", true, true); new CommandHelp(this).registerHelpCommand(); } }.runTaskLater(this, 0);
Thanks, unfortunately, still only /minecraft:help returns my command.
Hm, I confirmed that your first setup does not work. However, the second option does work for me.
With this code:
new BukkitRunnable() {
@Override
public void run() {
CommandAPIBukkit.unregister("help", true, true);
new CommandAPICommand("help")
.executes((sender, args) -> {
sender.sendMessage("You ran the custom /help command");
})
.register();
}
}.runTaskLater(this, 0);
I can get this log (verbose-ouputs
is true
):
[15:51:59] [Server thread/INFO]: Done (7.234s)! For help, type "help"
[15:51:59] [Server thread/INFO]: Linked 0 Bukkit permissions to commands
[15:51:59] [Server thread/INFO]: Reloading datapacks...
[15:51:59] [Server thread/INFO]: Loaded 7 recipes
[15:52:00] [Server thread/INFO]: Finished reloading datapacks
[15:52:00] [Server thread/INFO]: Unregistering command /help
[15:52:00] [Server thread/INFO]: Registering command /help
>help
[15:53:41] [Server thread/INFO]: You ran the custom /help command
>minecraft:help
[15:53:45] [Server thread/INFO]: You ran the custom /help command
Here, /help
is running my custom /help
implementation. What does your log look like?
This issue is the same for me.
Using this code, I can only execute minecraft:help
:
new BukkitRunnable() {
@Override
public void run() {
CommandAPIBukkit.unregister("help", true, true);
new CommandAPICommand("help")
.executes((sender, args) -> {
sender.sendMessage(Component.text().content("This is a custom /help implementation!"));
})
.register();
}
}.runTaskLater(this, 0);
This is what the log says:
[20:43:06 INFO]: [BugTestingCommandAPI] Enabling BugTestingCommandAPI v0.0.1
[20:43:06 INFO]: [CommandAPI] Hooked into Paper ServerResourcesReloadedEvent
[20:43:06 INFO]: Running delayed init tasks
[20:43:06 INFO]: [CommandAPI] Unregistering command /help
[20:43:06 INFO]: [CommandAPI] Registering command /help
[20:43:06 INFO]: [CommandAPI] Linking permissions to commands:
[20:43:06 INFO]: [CommandAPI] NONE -> /help
[20:43:06 INFO]: [CommandAPI] Linked 1 Bukkit permissions to commands
[20:43:06 INFO]: [CommandAPI] Reloading datapacks...
[20:43:06 INFO]: Loaded 7 recipes
[20:43:07 INFO]: [CommandAPI] Finished reloading datapacks
[20:43:07 INFO]: Done (3.075s)! For help, type "help"
[20:43:07 INFO]: Timings Reset
> help
[20:43:12 INFO]: Unknown command. Type "/help" for help.
> minecraft:help
[20:43:16 INFO]: This is a custom /help implementation!
@DerEchtePilz I think what's happening here is similar to #210 (comment). Does the fix over there (ee9077a) work for you here?
This also seems to be fixed now!
Implemented in CommandAPI 9.3.0.