summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThinkofdeath <thinkofdeath@spigotmc.org>2015-01-25 15:17:48 +0000
committerThinkofdeath <thinkofdeath@spigotmc.org>2015-01-25 15:17:48 +0000
commit15e81cf551facaee9e808b598655a6cf1274ffb1 (patch)
tree43d4dcc4ec9c3e7747808d7e56ce874ccfbdc35a
parent4b6df5adfeb92cd09428e59a963a6ee56d7d28d6 (diff)
downloadcraftbukkit-15e81cf551facaee9e808b598655a6cf1274ffb1.tar
craftbukkit-15e81cf551facaee9e808b598655a6cf1274ffb1.tar.gz
craftbukkit-15e81cf551facaee9e808b598655a6cf1274ffb1.tar.lz
craftbukkit-15e81cf551facaee9e808b598655a6cf1274ffb1.tar.xz
craftbukkit-15e81cf551facaee9e808b598655a6cf1274ffb1.zip
SPIGOT-449: Fix the wrong caller being used in chain execute commands
-rw-r--r--nms-patches/CommandBlockListenerAbstract.patch6
-rw-r--r--nms-patches/CommandExecute.patch23
-rw-r--r--src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java16
3 files changed, 30 insertions, 15 deletions
diff --git a/nms-patches/CommandBlockListenerAbstract.patch b/nms-patches/CommandBlockListenerAbstract.patch
index 9d672ec4..996b3f71 100644
--- a/nms-patches/CommandBlockListenerAbstract.patch
+++ b/nms-patches/CommandBlockListenerAbstract.patch
@@ -1,5 +1,5 @@
---- ../work/decompile-8eb82bde//net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-27 14:58:24.901254690 +0000
-+++ src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-27 14:58:24.905254690 +0000
+--- ../work/decompile-8eb82bde//net/minecraft/server/CommandBlockListenerAbstract.java 2015-01-25 15:16:21.156837700 +0000
++++ src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java 2015-01-25 15:16:21.156837700 +0000
@@ -4,6 +4,13 @@
import java.util.Date;
import java.util.concurrent.Callable;
@@ -82,7 +82,7 @@
+ if (!((VanillaCommandWrapper) commandBlockCommand).testPermission(bSender)) {
+ return 0;
+ }
-+ return ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommand(sender, as);
++ return ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommand(bSender, sender, as);
+ }
+
+ // Make sure this is a valid command
diff --git a/nms-patches/CommandExecute.patch b/nms-patches/CommandExecute.patch
index 5c42ada0..a0373aa5 100644
--- a/nms-patches/CommandExecute.patch
+++ b/nms-patches/CommandExecute.patch
@@ -1,14 +1,17 @@
---- ../work/decompile-8eb82bde//net/minecraft/server/CommandExecute.java 2015-01-04 23:24:40.781538505 +0000
-+++ src/main/java/net/minecraft/server/CommandExecute.java 2015-01-04 23:24:40.781538505 +0000
-@@ -2,6 +2,7 @@
+--- ../work/decompile-8eb82bde//net/minecraft/server/CommandExecute.java 2015-01-25 15:16:56.720837314 +0000
++++ src/main/java/net/minecraft/server/CommandExecute.java 2015-01-25 15:16:56.720837314 +0000
+@@ -2,6 +2,10 @@
import java.util.Collection;
import java.util.List;
++// CraftBukkit start
+import org.bukkit.craftbukkit.command.ProxiedNativeCommandSender;
++import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
++// CraftBukkit end
public class CommandExecute extends CommandAbstract {
-@@ -19,7 +20,7 @@
+@@ -19,7 +23,7 @@
return "commands.execute.usage";
}
@@ -17,7 +20,7 @@
if (astring.length < 5) {
throw new ExceptionUsage("commands.execute.usage", new Object[0]);
} else {
-@@ -52,12 +53,28 @@
+@@ -52,12 +56,30 @@
ICommandHandler icommandhandler = MinecraftServer.getServer().getCommandHandler();
try {
@@ -25,12 +28,14 @@
-
+ // CraftBukkit start
+ org.bukkit.command.CommandSender sender = null;
-+ if (icommandlistener.f() != null) {
-+ sender = icommandlistener.f().getBukkitEntity();
-+ } else if (icommandlistener instanceof DedicatedServer) {
++ if (icommandlistener instanceof DedicatedServer) {
+ sender = MinecraftServer.getServer().server.getConsoleSender();
+ } else if (icommandlistener instanceof TileEntityCommandListener) {
+ sender = ((TileEntityCommandListener) icommandlistener).sender;
++ } else if (VanillaCommandWrapper.lastSender != null) {
++ sender = VanillaCommandWrapper.lastSender;
++ }else if (icommandlistener.f() != null) {
++ sender = icommandlistener.f().getBukkitEntity();
+ } else {
+ throw new CommandException("Unhandled executor " + icommandlistener.getClass().getSimpleName(), new Object[0]);
+ }
@@ -48,7 +53,7 @@
throw new CommandException("commands.execute.failed", new Object[] { s, entity.getName()});
}
}
-@@ -70,4 +87,11 @@
+@@ -70,4 +92,11 @@
public boolean isListStart(String[] astring, int i) {
return i == 0;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
index 2e85c12b..5be09a34 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
@@ -10,6 +10,7 @@ import org.apache.logging.log4j.Level;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.command.ProxiedCommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
import org.bukkit.command.defaults.*;
import org.bukkit.craftbukkit.CraftServer;
@@ -39,7 +40,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
if (!testPermission(sender)) return true;
ICommandListener icommandlistener = getListener(sender);
- dispatchVanillaCommand(icommandlistener, args);
+ dispatchVanillaCommand(sender, icommandlistener, args);
return true;
}
@@ -51,7 +52,9 @@ public final class VanillaCommandWrapper extends VanillaCommand {
return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0));
}
- public final int dispatchVanillaCommand(ICommandListener icommandlistener, String[] as) {
+ public static CommandSender lastSender = null; // Nasty :(
+
+ public final int dispatchVanillaCommand(CommandSender bSender, ICommandListener icommandlistener, String[] as) {
// Copied from net.minecraft.server.CommandHandler
int i = getPlayerListSize(as);
int j = 0;
@@ -71,6 +74,8 @@ public final class VanillaCommandWrapper extends VanillaCommand {
while (iterator.hasNext()) {
Entity entity = iterator.next();
+ CommandSender oldSender = lastSender;
+ lastSender = bSender;
try {
as[i] = entity.getUniqueID().toString();
vanillaCommand.execute(icommandlistener, as);
@@ -83,7 +88,9 @@ public final class VanillaCommandWrapper extends VanillaCommand {
ChatMessage chatmessage = new ChatMessage(commandexception.getMessage(), commandexception.getArgs());
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
icommandlistener.sendMessage(chatmessage);
- }
+ } finally {
+ lastSender = oldSender;
+ }
}
as[i] = s2;
} else {
@@ -140,6 +147,9 @@ public final class VanillaCommandWrapper extends VanillaCommand {
if (sender instanceof ConsoleCommandSender) {
return ((CraftServer) sender.getServer()).getServer();
}
+ if (sender instanceof ProxiedCommandSender) {
+ return ((ProxiedNativeCommandSender) sender).getHandle();
+ }
return null;
}