diff --git a/nms-patches/CommandDispatcher.patch b/nms-patches/CommandDispatcher.patch index 3067bda754..945584b0b2 100644 --- a/nms-patches/CommandDispatcher.patch +++ b/nms-patches/CommandDispatcher.patch @@ -1,13 +1,14 @@ --- a/net/minecraft/server/CommandDispatcher.java +++ b/net/minecraft/server/CommandDispatcher.java -@@ -26,12 +26,20 @@ +@@ -26,12 +26,21 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// CraftBukkit start +import com.google.common.base.Joiner; -+import org.apache.logging.log4j.Level; ++import java.util.LinkedHashSet; +import org.bukkit.craftbukkit.command.VanillaCommandWrapper; ++import org.bukkit.event.player.PlayerCommandSendEvent; +import org.bukkit.event.server.ServerCommandEvent; +// CraftBukkit end + @@ -22,7 +23,7 @@ CommandAdvancement.a(this.b); CommandExecute.a(this.b); CommmandBossBar.a(this.b); -@@ -100,6 +108,11 @@ +@@ -100,6 +109,11 @@ this.b.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> { CommandDispatcher.a.warn("Ambiguity between arguments {} and {} with inputs: {}", this.b.getPath(commandnode1), this.b.getPath(commandnode2), collection); }); @@ -34,7 +35,7 @@ this.b.setConsumer((commandcontext, flag, i) -> { ((CommandListenerWrapper) commandcontext.getSource()).a(commandcontext, flag, i); }); -@@ -114,8 +127,49 @@ +@@ -114,8 +128,49 @@ } @@ -85,7 +86,7 @@ if (s.startsWith("/")) { s = s.substring(1); -@@ -126,7 +180,6 @@ +@@ -126,7 +181,6 @@ byte b0; try { @@ -93,7 +94,7 @@ ChatComponentText chatcomponenttext; try { -@@ -135,65 +188,80 @@ +@@ -135,65 +189,95 @@ return i; } catch (CommandException commandexception) { commandlistenerwrapper.sendFailureMessage(commandexception.a()); @@ -184,6 +185,7 @@ public void a(EntityPlayer entityplayer) { - HashMap hashmap = Maps.newHashMap(); +- RootCommandNode rootcommandnode = new RootCommandNode(); + // CraftBukkit start + // Register Vanilla commands into builtRoot as before + Map hashmap = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues @@ -194,10 +196,25 @@ + this.a(vanilla, vanillaRoot, entityplayer.getCommandListener(), (Map) hashmap); + + // Now build the global commands in a second pass - RootCommandNode rootcommandnode = new RootCommandNode(); ++ RootCommandNode rootcommandnode = new RootCommandNode(); hashmap.put(this.b.getRoot(), rootcommandnode); this.a(this.b.getRoot(), rootcommandnode, entityplayer.getCommandListener(), (Map) hashmap); ++ ++ Collection bukkit = new LinkedHashSet<>(); ++ for (CommandNode node : rootcommandnode.getChildren()) { ++ bukkit.add(node.getName()); ++ } ++ ++ PlayerCommandSendEvent event = new PlayerCommandSendEvent(entityplayer.getBukkitEntity(), new LinkedHashSet<>(bukkit)); ++ event.getPlayer().getServer().getPluginManager().callEvent(event); ++ ++ // Remove labels that were removed during the event ++ for (String orig : bukkit) { ++ if (!event.getCommands().contains(orig)) { ++ rootcommandnode.removeCommand(orig); ++ } ++ } + // CraftBukkit end entityplayer.playerConnection.sendPacket(new PacketPlayOutCommands(rootcommandnode)); } diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java index 1196df6b6c..98592a3e63 100644 --- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java @@ -34,6 +34,13 @@ public abstract class CommandNode implements Comparable> { private final RedirectModifier modifier; private final boolean forks; private Command command; + // CraftBukkit start + public void removeCommand(String name) { + children.remove(name); + literals.remove(name); + arguments.remove(name); + } + // CraftBukkit end protected CommandNode(final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks) { this.command = command;