From 549d9b012078466bd36c6185fe6e1a4bcf311b8c Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 31 Jul 2018 10:46:09 +1000 Subject: SPIGOT-4029: Add event for commands being sent to client --- nms-patches/CommandDispatcher.patch | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'nms-patches') diff --git a/nms-patches/CommandDispatcher.patch b/nms-patches/CommandDispatcher.patch index 3067bda7..945584b0 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)); } -- cgit v1.2.3