diff --git a/pandalib-core/src/main/resources/fr/pandacube/lib/core/mc_version/mcversion.json b/pandalib-core/src/main/resources/fr/pandacube/lib/core/mc_version/mcversion.json index f932771..6e9ccbd 100644 --- a/pandalib-core/src/main/resources/fr/pandacube/lib/core/mc_version/mcversion.json +++ b/pandalib-core/src/main/resources/fr/pandacube/lib/core/mc_version/mcversion.json @@ -68,7 +68,9 @@ "1.20.5": 766, "1.20.6": 766, "1.21": 767, - "1.21.1": 767 + "1.21.1": 767, + "1.21.2": 768, + "1.21.3": 768 }, "versionsOfProtocol": { "4": [ @@ -223,6 +225,10 @@ "767": [ "1.21", "1.21.1" + ], + "768": [ + "1.21.2", + "1.21.3" ] } } \ No newline at end of file diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java index 9d1d78e..1c666d3 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java @@ -113,7 +113,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand commandNode; + protected LiteralCommandNode commandNode; /** * The command requested aliases. */ @@ -134,11 +134,9 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand { updateVanillaPaperDispatcher(event.registrar().getDispatcher()); + commandNode = buildCommand().build(); + postBuildCommand(commandNode); + if (vanillaPaperDispatcher.getRoot().getChild(commandNode.getName()) != null) { Log.info("Command /" + commandNode.getName() + " found in the vanilla dispatcher during initial command registration. Replacing it by force."); vanillaPaperDispatcher.getRoot().getChildren().removeIf(c -> c.getName().equals(commandNode.getName())); @@ -177,40 +178,42 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand { - if (vanillaPaperDispatcher == null) - return; + Bukkit.getServer().getScheduler().runTask(plugin, () -> { + if (vanillaPaperDispatcher == null) + return; - Set forceRegistrationAgain = new HashSet<>(); - forceRegistrationAgain.add(commandNode.getName()); - if (registrationPolicy == RegistrationPolicy.ALL) - forceRegistrationAgain.addAll(List.of(aliases)); + Set forceRegistrationAgain = new HashSet<>(); + forceRegistrationAgain.add(commandNode.getName()); + if (registrationPolicy == RegistrationPolicy.ALL) + forceRegistrationAgain.addAll(List.of(aliases)); - for (String aliasToForce : forceRegistrationAgain) { - CommandNode actualNode = vanillaPaperDispatcher.getRoot().getChild(aliasToForce); - if (actualNode != null) { - //Log.info("Forcing registration of alias /" + aliasToForce + " for command /" + commandNode.getName() + ": replacing " + getCommandIdentity(actualNode) + "?"); - if (PluginCommandNode.REFLECT.get().isInstance(actualNode)) { - PluginCommandNode pcn = wrap(actualNode, PluginCommandNode.class); - if (pcn.getPlugin().equals(plugin)) - return; + for (String aliasToForce : forceRegistrationAgain) { + CommandNode actualNode = vanillaPaperDispatcher.getRoot().getChild(aliasToForce); + if (actualNode != null) { + //Log.info("Forcing registration of alias /" + aliasToForce + " for command /" + commandNode.getName() + ": replacing " + getCommandIdentity(actualNode) + "?"); + if (PluginCommandNode.REFLECT.get().isInstance(actualNode)) { + PluginCommandNode pcn = wrap(actualNode, PluginCommandNode.class); + if (pcn.getPlugin().equals(plugin)) + return; + } + else if (BukkitCommandNode.REFLECT.get().isInstance(actualNode)) { + BukkitCommandNode bcn = wrap(actualNode, BukkitCommandNode.class); + if (bcn.getBukkitCommand() instanceof PluginCommand pc && pc.getPlugin().equals(plugin)) + return; + } + vanillaPaperDispatcher.getRoot().getChildren().removeIf(c -> c.getName().equals(aliasToForce)); } - else if (BukkitCommandNode.REFLECT.get().isInstance(actualNode)) { - BukkitCommandNode bcn = wrap(actualNode, BukkitCommandNode.class); - if (bcn.getBukkitCommand() instanceof PluginCommand pc && pc.getPlugin().equals(plugin)) - return; - } - vanillaPaperDispatcher.getRoot().getChildren().removeIf(c -> c.getName().equals(aliasToForce)); - } /*else { Log.info("Forcing registration of alias /" + aliasToForce + " for command /" + commandNode.getName() + ": no command found for alias. Adding alias."); }*/ - LiteralCommandNode newPCN = unwrap(new PluginCommandNode(aliasToForce, plugin.getPluginMeta(), commandNode, description)); - vanillaPaperDispatcher.getRoot().addChild(newPCN); - } + LiteralCommandNode newPCN = unwrap(new PluginCommandNode(aliasToForce, plugin.getPluginMeta(), commandNode, description)); + vanillaPaperDispatcher.getRoot().addChild(newPCN); + } + }); + }); + }