summaryrefslogtreecommitdiffstats
path: root/nms-patches/CommandExecute.patch
blob: 6b7a5aab0d8a99115fdc3242f3d5afd57ba9042c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--- a/net/minecraft/server/CommandExecute.java
+++ b/net/minecraft/server/CommandExecute.java
@@ -4,6 +4,10 @@
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.command.ProxiedNativeCommandSender;
+import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
+// CraftBukkit end
 
 public class CommandExecute extends CommandAbstract {
 
@@ -50,7 +54,10 @@
             }
 
             String s = a(astring, b0);
-            ICommandListener icommandlistener1 = new ICommandListener() {
+            // CraftBukkit start - name class
+            class ProxyListener implements ICommandListener {
+                private final ICommandListener base = icommandlistener;
+            // CraftBukkit end
                 public String getName() {
                     return entity.getName();
                 }
@@ -95,25 +102,57 @@
                     return entity.h();
                 }
             };
+            ICommandListener icommandlistener1 = new ProxyListener(); // CraftBukkit
             ICommandHandler icommandhandler = minecraftserver.getCommandHandler();
 
             try {
-                int j = icommandhandler.a(icommandlistener1, s);
+                // CraftBukkit start
+                org.bukkit.command.CommandSender sender = null;
+                ICommandListener listener = icommandlistener;
+                while (sender == null) {
+                    if (listener instanceof DedicatedServer) {
+                        sender = minecraftserver.server.getConsoleSender();
+                    } else if (listener instanceof CommandBlockListenerAbstract) {
+                        sender = ((CommandBlockListenerAbstract) listener).sender;
+                    } else if (listener instanceof ProxyListener) {
+                        listener = ((ProxyListener) listener).base; // Search deeper
+                    } else if (VanillaCommandWrapper.lastSender != null) {
+                        sender = VanillaCommandWrapper.lastSender;
+                    } else if (listener.f() != null) {
+                        sender = listener.f().getBukkitEntity();
+                    } else {
+                        throw new CommandException("Unhandled executor " + icommandlistener.getClass().getSimpleName(), new Object[0]);
+                    }
+                }
+                int j = CommandBlockListenerAbstract.executeCommand(icommandlistener1, new ProxiedNativeCommandSender(icommandlistener1, sender, entity.getBukkitEntity()), s); 
+                // CraftBukkit end
 
                 if (j < 1) {
                     throw new CommandException("commands.execute.allInvocationsFailed", new Object[] { s});
                 }
             } catch (Throwable throwable) {
+                // CraftBukkit start
+                if (throwable instanceof CommandException) {
+                    throw (CommandException) throwable;
+                }
+                // CraftBukkit end
                 throw new CommandException("commands.execute.failed", new Object[] { s, entity.getName()});
             }
         }
     }
 
     public List<String> tabComplete(MinecraftServer minecraftserver, ICommandListener icommandlistener, String[] astring, @Nullable BlockPosition blockposition) {
-        return astring.length == 1 ? a(astring, minecraftserver.getPlayers()) : (astring.length > 1 && astring.length <= 4 ? a(astring, 1, blockposition) : (astring.length > 5 && astring.length <= 8 && "detect".equals(astring[4]) ? a(astring, 5, blockposition) : (astring.length == 9 && "detect".equals(astring[4]) ? a(astring, (Collection) Block.REGISTRY.keySet()) : Collections.emptyList())));
+        return astring.length == 1 ? a(astring, minecraftserver.getPlayers()) : (astring.length > 1 && astring.length <= 4 ? a(astring, 1, blockposition) : (astring.length > 5 && astring.length <= 8 && "detect".equals(astring[4]) ? a(astring, 5, blockposition) : (astring.length == 9 && "detect".equals(astring[4]) ? a(astring, (Collection) Block.REGISTRY.keySet()) : Collections.<String>emptyList()))); // CraftBukkit - decompile error
     }
 
     public boolean isListStart(String[] astring, int i) {
         return i == 0;
     }
+
+    // CraftBukkit start - fix decompiler error
+    @Override
+    public int compareTo(ICommand o) {
+        return a((ICommand) o);
+    }
+    // CraftBukkit end
 }