SPIGOT-3376: Fix nested functions

This commit is contained in:
md_5 2017-06-26 08:27:25 +10:00
parent 258575110f
commit de76085596
3 changed files with 42 additions and 28 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/CommandBlockListenerAbstract.java --- a/net/minecraft/server/CommandBlockListenerAbstract.java
+++ b/net/minecraft/server/CommandBlockListenerAbstract.java +++ b/net/minecraft/server/CommandBlockListenerAbstract.java
@@ -4,6 +4,13 @@ @@ -4,6 +4,14 @@
import java.util.Date; import java.util.Date;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -9,12 +9,13 @@
+import org.bukkit.craftbukkit.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
+import com.google.common.base.Joiner; +import com.google.common.base.Joiner;
+import java.util.logging.Level; +import java.util.logging.Level;
+import org.bukkit.command.CommandSender;
+// CraftBukkit end +// CraftBukkit end
+ +
public abstract class CommandBlockListenerAbstract implements ICommandListener { public abstract class CommandBlockListenerAbstract implements ICommandListener {
private static final SimpleDateFormat a = new SimpleDateFormat("HH:mm:ss"); private static final SimpleDateFormat a = new SimpleDateFormat("HH:mm:ss");
@@ -15,6 +22,7 @@ @@ -15,6 +23,7 @@
private String g = ""; private String g = "";
private String h = "@"; private String h = "@";
private final CommandObjectiveExecutor i = new CommandObjectiveExecutor(); private final CommandObjectiveExecutor i = new CommandObjectiveExecutor();
@ -22,7 +23,7 @@
public CommandBlockListenerAbstract() {} public CommandBlockListenerAbstract() {}
@@ -107,7 +115,9 @@ @@ -107,7 +116,9 @@
if (minecraftserver != null && minecraftserver.M() && minecraftserver.getEnableCommandBlock()) { if (minecraftserver != null && minecraftserver.M() && minecraftserver.getEnableCommandBlock()) {
try { try {
this.f = null; this.f = null;
@ -33,7 +34,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Executing command block"); CrashReport crashreport = CrashReport.a(throwable, "Executing command block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Command to be executed"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Command to be executed");
@@ -149,6 +159,138 @@ @@ -149,6 +160,163 @@
} }
} }
@ -167,6 +168,31 @@
+ +
+ return commands; + return commands;
+ } + }
+
+ public static CommandSender unwrapSender(ICommandListener listener) {
+ org.bukkit.command.CommandSender sender = null;
+ while (sender == null) {
+ if (listener instanceof DedicatedServer) {
+ sender = ((DedicatedServer) listener).console;
+ } else if (listener instanceof RemoteControlCommandListener) {
+ sender = ((DedicatedServer) listener).remoteConsole;
+ } else if (listener instanceof CommandBlockListenerAbstract) {
+ sender = ((CommandBlockListenerAbstract) listener).sender;
+ } else if (listener instanceof CustomFunctionData.CustomFunctionListener) {
+ sender = ((CustomFunctionData.CustomFunctionListener) listener).sender;
+ } else if (listener instanceof CommandListenerWrapper) {
+ listener = ((CommandListenerWrapper) listener).base; // Search deeper
+ } else if (VanillaCommandWrapper.lastSender != null) {
+ sender = VanillaCommandWrapper.lastSender;
+ } else if (listener.f() != null) {
+ sender = listener.f().getBukkitEntity();
+ } else {
+ throw new RuntimeException("Unhandled executor " + listener.getClass().getSimpleName());
+ }
+ }
+
+ return sender;
+ }
+ // CraftBukkit end + // CraftBukkit end
+ +
public String getName() { public String getName() {

View file

@ -11,7 +11,7 @@
public class CommandExecute extends CommandAbstract { public class CommandExecute extends CommandAbstract {
@@ -59,26 +63,61 @@ @@ -59,26 +63,41 @@
} }
String s = a(astring, b0); String s = a(astring, b0);
@ -22,27 +22,7 @@
try { try {
- int i = icommandhandler.a(commandlistenerwrapper, s); - int i = icommandhandler.a(commandlistenerwrapper, s);
+ // CraftBukkit start + // CraftBukkit start
+ org.bukkit.command.CommandSender sender = null; + org.bukkit.command.CommandSender sender = CommandBlockListenerAbstract.unwrapSender(icommandlistener);
+ ICommandListener listener = icommandlistener;
+ while (sender == null) {
+ if (listener instanceof DedicatedServer) {
+ sender = minecraftserver.console;
+ } else if (listener instanceof RemoteControlCommandListener) {
+ sender = minecraftserver.remoteConsole;
+ } else if (listener instanceof CommandBlockListenerAbstract) {
+ sender = ((CommandBlockListenerAbstract) listener).sender;
+ } else if (listener instanceof CustomFunctionData.CustomFunctionListener) {
+ sender = ((CustomFunctionData.CustomFunctionListener) listener).sender;
+ } else if (listener instanceof CommandListenerWrapper) {
+ listener = ((CommandListenerWrapper) 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 i = CommandBlockListenerAbstract.executeCommand(commandlistenerwrapper, new ProxiedNativeCommandSender(commandlistenerwrapper, sender, entity.getBukkitEntity()), s); + int i = CommandBlockListenerAbstract.executeCommand(commandlistenerwrapper, new ProxiedNativeCommandSender(commandlistenerwrapper, sender, entity.getBukkitEntity()), s);
+ // CraftBukkit end + // CraftBukkit end

View file

@ -1,11 +1,19 @@
--- a/net/minecraft/server/CustomFunction.java --- a/net/minecraft/server/CustomFunction.java
+++ b/net/minecraft/server/CustomFunction.java +++ b/net/minecraft/server/CustomFunction.java
@@ -122,7 +122,7 @@ @@ -122,7 +122,15 @@
} }
public void a(CustomFunctionData customfunctiondata, ICommandListener icommandlistener, ArrayDeque<CustomFunctionData.a> arraydeque, int i) { public void a(CustomFunctionData customfunctiondata, ICommandListener icommandlistener, ArrayDeque<CustomFunctionData.a> arraydeque, int i) {
- customfunctiondata.a().a(icommandlistener, this.a); - customfunctiondata.a().a(icommandlistener, this.a);
+ CommandBlockListenerAbstract.executeSafely(icommandlistener, ((CustomFunctionData.CustomFunctionListener) icommandlistener).sender, this.a); // CraftBukkit + // CraftBukkit start
+ org.bukkit.command.CommandSender sender;
+ if (icommandlistener instanceof CustomFunctionData.CustomFunctionListener) {
+ sender = ((CustomFunctionData.CustomFunctionListener) icommandlistener).sender;
+ } else {
+ sender = CommandBlockListenerAbstract.unwrapSender(icommandlistener);
+ }
+ CommandBlockListenerAbstract.executeSafely(icommandlistener, sender, this.a);
+ // CraftBukkit end
} }
public String toString() { public String toString() {