SPIGOT-4046: Fix selectors in tick functions

This commit is contained in:
md_5 2018-07-19 10:58:31 +10:00
parent 80f4c10c8f
commit fc1b107579
3 changed files with 59 additions and 26 deletions

View File

@ -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.<init>(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.<init>(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;

View File

@ -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<CustomFunctionData.a> 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() {

View File

@ -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();