From fc1b107579cf85654e84cbaf074dd5eaceeae3c6 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 19 Jul 2018 10:58:31 +1000 Subject: SPIGOT-4046: Fix selectors in tick functions --- .../craftbukkit/command/VanillaCommandWrapper.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index f6bc346c..b57eb251 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(); -- cgit v1.2.3