From fc1b107579cf85654e84cbaf074dd5eaceeae3c6 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 19 Jul 2018 10:58:31 +1000 Subject: [PATCH] SPIGOT-4046: Fix selectors in tick functions --- nms-patches/CommandDispatcher.patch | 39 +++++++------------ nms-patches/CustomFunction.patch | 16 ++++++++ .../command/VanillaCommandWrapper.java | 30 ++++++++++++++ 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/nms-patches/CommandDispatcher.patch b/nms-patches/CommandDispatcher.patch index 0c03bf60ff..b33f9d6ec0 100644 --- a/nms-patches/CommandDispatcher.patch +++ b/nms-patches/CommandDispatcher.patch @@ -1,12 +1,13 @@ --- a/net/minecraft/server/CommandDispatcher.java +++ b/net/minecraft/server/CommandDispatcher.java -@@ -26,12 +26,19 @@ +@@ -26,12 +26,20 @@ 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 org.bukkit.craftbukkit.command.VanillaCommandWrapper; +import org.bukkit.event.server.ServerCommandEvent; +// CraftBukkit end + @@ -21,7 +22,7 @@ CommandAdvancement.a(this.b); CommandExecute.a(this.b); CommmandBossBar.a(this.b); -@@ -100,6 +107,11 @@ +@@ -100,6 +108,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); }); @@ -33,7 +34,7 @@ this.b.setConsumer((commandcontext, flag, i) -> { ((CommandListenerWrapper) commandcontext.getSource()).a(commandcontext, flag, i); }); -@@ -114,8 +126,63 @@ +@@ -114,8 +127,49 @@ } @@ -78,27 +79,13 @@ + } + + public int a(CommandListenerWrapper commandlistenerwrapper, String s, String label) { -+ // Some commands use the worldserver variable but we leave it full of null values, -+ // so we must temporarily populate it with the world of the commandsender -+ WorldServer[] prev = MinecraftServer.getServer().worldServer; -+ MinecraftServer server = MinecraftServer.getServer(); -+ server.worldServer = new WorldServer[server.worlds.size()]; -+ server.worldServer[0] = (WorldServer) commandlistenerwrapper.getWorld(); -+ int bpos = 0; -+ for (int pos = 1; pos < server.worldServer.length; pos++) { -+ WorldServer world = server.worlds.get(bpos++); -+ if (server.worldServer[0] == world) { -+ pos--; -+ continue; -+ } -+ server.worldServer[pos] = world; -+ } ++ VanillaCommandWrapper.WorldRescueContext rescue = new VanillaCommandWrapper.WorldRescueContext().start(commandlistenerwrapper.getWorld()); + String s1 = label; + // CraftBukkit end if (s.startsWith("/")) { s = s.substring(1); -@@ -126,7 +193,6 @@ +@@ -126,7 +180,6 @@ byte b0; try { @@ -106,7 +93,7 @@ ChatComponentText chatcomponenttext; try { -@@ -135,54 +201,59 @@ +@@ -135,54 +188,59 @@ return i; } catch (CommandException commandexception) { commandlistenerwrapper.sendFailureMessage(commandexception.a()); @@ -158,17 +145,17 @@ } catch (Exception exception) { - chatcomponenttext = new ChatComponentText; - } -- -- chatcomponenttext.(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); -- ChatComponentText chatcomponenttext1 = chatcomponenttext; + ChatMessage chatmessage1 = new ChatMessage("command.failed", new Object[0]); -- if (CommandDispatcher.a.isDebugEnabled()) { -- StackTraceElement[] astacktraceelement = exception.getStackTrace(); +- chatcomponenttext.(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); +- ChatComponentText chatcomponenttext1 = chatcomponenttext; + chatcomponenttext = new ChatComponentText(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); + if (CommandDispatcher.a.isDebugEnabled()) { + StackTraceElement[] astacktraceelement = exception.getStackTrace(); +- if (CommandDispatcher.a.isDebugEnabled()) { +- StackTraceElement[] astacktraceelement = exception.getStackTrace(); +- - for (int k = 0; k < Math.min(astacktraceelement.length, 3); ++k) { - chatcomponenttext1.a("\n\n").a(astacktraceelement[k].getMethodName()).a("\n ").a(astacktraceelement[k].getFileName()).a(":").a(String.valueOf(astacktraceelement[k].getLineNumber())); + for (int k = 0; k < Math.min(astacktraceelement.length, 3); ++k) { @@ -189,7 +176,7 @@ + } } finally { commandlistenerwrapper.getServer().methodProfiler.e(); -+ MinecraftServer.getServer().worldServer = prev; // CraftBukkit ++ rescue.end(); // CraftBukkit } return b0; diff --git a/nms-patches/CustomFunction.patch b/nms-patches/CustomFunction.patch index 034c354659..b457151c5f 100644 --- a/nms-patches/CustomFunction.patch +++ b/nms-patches/CustomFunction.patch @@ -9,3 +9,19 @@ if (parseresults.getReader().canRead()) { if (parseresults.getExceptions().size() == 1) { +@@ -142,7 +142,14 @@ + } + + public void a(CustomFunctionData customfunctiondata, CommandListenerWrapper commandlistenerwrapper, ArrayDeque arraydeque, int i) throws CommandSyntaxException { +- customfunctiondata.d().execute(new ParseResults(this.a.getContext().withSource(commandlistenerwrapper), this.a.getReader(), this.a.getExceptions())); ++ // CraftBukkit start ++ org.bukkit.craftbukkit.command.VanillaCommandWrapper.WorldRescueContext rescue = new org.bukkit.craftbukkit.command.VanillaCommandWrapper.WorldRescueContext().start(commandlistenerwrapper.getWorld()); ++ try { ++ customfunctiondata.d().execute(new ParseResults(this.a.getContext().withSource(commandlistenerwrapper), this.a.getReader(), this.a.getExceptions())); ++ } finally { ++ rescue.end(); ++ } ++ // CraftBukkit end + } + + public String toString() { diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index f6bc346c33..b57eb251a9 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java +++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java @@ -12,6 +12,7 @@ import net.minecraft.server.CommandListenerWrapper; import net.minecraft.server.DedicatedServer; import net.minecraft.server.EntityMinecartCommandBlock; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.WorldServer; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.command.BlockCommandSender; @@ -64,6 +65,35 @@ public final class VanillaCommandWrapper extends BukkitCommand { return results; } + public static class WorldRescueContext { + + private WorldServer[] prev; + + public WorldRescueContext start(WorldServer def) { + // Some commands use the worldserver variable but we leave it full of null values, + // so we must temporarily populate it with the world of the commandsender + prev = MinecraftServer.getServer().worldServer; + MinecraftServer server = MinecraftServer.getServer(); + server.worldServer = new WorldServer[server.worlds.size()]; + server.worldServer[0] = def; + int bpos = 0; + for (int pos = 1; pos < server.worldServer.length; pos++) { + WorldServer world = server.worlds.get(bpos++); + if (server.worldServer[0] == world) { + pos--; + continue; + } + server.worldServer[pos] = world; + } + + return this; + } + + public void end() { + MinecraftServer.getServer().worldServer = prev; + } + } + private CommandListenerWrapper getListener(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle().getCommandListener();