CommandAPI icon indicating copy to clipboard operation
CommandAPI copied to clipboard

minecraft:reload break my own vanilla commands

Open FastJoe0 opened this issue 11 months ago • 2 comments

CommandAPI version

9.7.0

Minecraft version

1.21.4

Are you shading the CommandAPI?

Yes

What I did

@Override
public void onLoad() {
    CommandAPI.onLoad(new CommandAPIBukkitConfig(this)
        .shouldHookPaperReload(true)
        .skipReloadDatapacks(true)
        .verboseOutput(true)
    );
    CommandAPI.unregister("tp", true);
    CommandAPI.unregister("teleport", true)
}

@Override
public void onEnable() {
    CommandAPI.onEnable();

    new CommandTp(this).registerTpCommand();

}

What actually happened

After loading my plugin, another plugin (TreasureMapsPlus) at the end of loading the server executes the minecraft:reload command which break my minecraft vanilla command (/tp).

You don't even need the TreasureMapsPlus plugin to reproduce this bug. Just execute minecraft:reload on a running server. All minecraft vanilla commands that we have created based on already existing ones in vanilla will be broken.

minecraft:reload [23:49:47 INFO]: Reloading! [23:49:48 INFO]: Loaded 1370 recipes [23:49:48 INFO]: Loaded 1481 advancements [23:49:48 INFO]: [CommandAPI] /minecraft:reload detected. Reloading CommandAPI commands! [23:49:48 INFO]: [CommandAPI] Reloading datapacks... [23:49:48 INFO]: Loaded 1370 recipes [23:49:48 INFO]: Loaded 1481 advancements [23:49:48 INFO]: [CommandAPI] Finished reloading datapacks

What should have happened

minecraft:reload should reload the modified vanilla commands.

Server logs and CommandAPI config

CommandAPI config:

shouldHookPaperReload(true)
skipReloadDatapacks(true)
.verboseOutput(true)

Server logs: https://hastebin.com/share/pupedonijo.markdown

Other

https://github.com/CommandAPI/CommandAPI/commit/feb318825acac932f360ca1005987312c1358837

FastJoe0 avatar Jan 10 '25 23:01 FastJoe0

Yeah, I can definitely see why this happens, though the commit you linked has nothing to do with the issue. I would give you a more in-depth explanation, but I am not at a computer at the moment, so I don't want to, but basically: When you execute minecraft:reload on Paper, the command dispatcher is replaced completely. This also means that all Vanilla commands are registered there, as well as plugin commands. The commit you linked successfully places any CommandAPI-registered command back into the dispatcher after the reload but any unregister information is lost.

DerEchtePilz avatar Jan 10 '25 23:01 DerEchtePilz

You may be able to temporarily fix this by registering your own EventHandler for Paper's ServerResourcesReloadedEvent. If you register your event to run before the CommandAPI, you can unregister the teleport commands, then the CommandAPI's Listener will re-register your command.

willkroboth avatar Jan 11 '25 12:01 willkroboth

Fixed in version 11.0.0

DerEchtePilz avatar Oct 04 '25 15:10 DerEchtePilz