13
0
geforkt von Mirrors/Paper

Add basic support for executing commands from signs

TODO: Wrap the player in to allow for plugins to handle it better

By: Thinkofdeath <thinkofdeath@spigotmc.org>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2014-12-05 23:10:47 +00:00
Ursprung af5d08b285
Commit b8e4f690f8
3 geänderte Dateien mit 119 neuen und 111 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,5 @@
--- ../work/decompile-8eb82bde//net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-02 20:23:51.921621335 +0000 --- ../work/decompile-8eb82bde//net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-05 23:10:24.921614234 +0000
+++ src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-02 20:23:10.809622247 +0000 +++ src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java 2014-12-05 23:04:53.325621594 +0000
@@ -4,6 +4,13 @@ @@ -4,6 +4,13 @@
import java.util.Date; import java.util.Date;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -22,72 +22,77 @@
public CommandBlockListenerAbstract() {} public CommandBlockListenerAbstract() {}
@@ -79,7 +87,110 @@ @@ -79,7 +87,10 @@
try { try {
this.d = null; this.d = null;
- this.b = icommandhandler.a(this, this.e); - this.b = icommandhandler.a(this, this.e);
+ // this.b = icommandhandler.a(this, this.e); + // this.b = icommandhandler.a(this, this.e);
+ // CraftBukkit start - Handle command block commands using Bukkit dispatcher + // CraftBukkit start - Handle command block commands using Bukkit dispatcher
+ org.bukkit.command.SimpleCommandMap commandMap = minecraftserver.server.getCommandMap(); + this.b= executeCommand(this, sender, this.e);
+ // CraftBukkit end
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Executing command block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Command to be executed");
@@ -91,8 +102,123 @@
} else {
this.b = 0;
}
+ }
+
+ // CraftBukkit start
+
+ public static int executeCommand(ICommandListener sender, org.bukkit.command.CommandSender bSender, String command) {
+ org.bukkit.command.SimpleCommandMap commandMap = sender.getWorld().getServer().getCommandMap();
+ Joiner joiner = Joiner.on(" "); + Joiner joiner = Joiner.on(" ");
+ String command = this.e; + if (command.startsWith("/")) {
+ if (this.e.startsWith("/")) { + command = command.substring(1);
+ command = this.e.substring(1);
+ } + }
+ String[] args = command.split(" "); + String[] args = command.split(" ");
+ ArrayList<String[]> commands = new ArrayList<String[]>(); + ArrayList<String[]> commands = new ArrayList<String[]>();
+ +
+ // Block disallowed commands + // Block disallowed commands
+ if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("kick") || args[0].equalsIgnoreCase("op") || + if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("kick") || args[0].equalsIgnoreCase("op")
+ args[0].equalsIgnoreCase("deop") || args[0].equalsIgnoreCase("ban") || args[0].equalsIgnoreCase("ban-ip") || + || args[0].equalsIgnoreCase("deop") || args[0].equalsIgnoreCase("ban") || args[0].equalsIgnoreCase("ban-ip")
+ args[0].equalsIgnoreCase("pardon") || args[0].equalsIgnoreCase("pardon-ip") || args[0].equalsIgnoreCase("reload")) { + || args[0].equalsIgnoreCase("pardon") || args[0].equalsIgnoreCase("pardon-ip") || args[0].equalsIgnoreCase("reload")) {
+ this.b = 0; + return 0;
+ return;
+ } + }
+ +
+ // If the world has no players don't run + // If the world has no players don't run
+ if (this.getWorld().players.isEmpty()) { + if (sender.getWorld().players.isEmpty()) {
+ this.b = 0; + return 0;
+ return;
+ } + }
+ +
+ // Handle vanilla commands; + // Handle vanilla commands;
+ org.bukkit.command.Command commandBlockCommand = commandMap.getCommand(args[0]); + org.bukkit.command.Command commandBlockCommand = commandMap.getCommand(args[0]);
+ if (minecraftserver.server.getCommandBlockOverride(args[0])) { + if (sender.getWorld().getServer().getCommandBlockOverride(args[0])) {
+ commandBlockCommand = commandMap.getCommand("minecraft:" + args[0]); + commandBlockCommand = commandMap.getCommand("minecraft:" + args[0]);
+ } + }
+ if (commandBlockCommand instanceof VanillaCommandWrapper) { + if (commandBlockCommand instanceof VanillaCommandWrapper) {
+ this.b = ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommandBlock(this, this.e); + return ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommandBlock(sender, command);
+ return;
+ } + }
+ +
+ // Make sure this is a valid command + // Make sure this is a valid command
+ if (commandMap.getCommand(args[0]) == null) { + if (commandMap.getCommand(args[0]) == null) {
+ this.b = 0; + return 0;
+ return;
+ } + }
+ +
+ // testfor command requires special handling + // testfor command requires special handling
+ if (args[0].equalsIgnoreCase("testfor")) { + if (args[0].equalsIgnoreCase("testfor")) {
+ if (args.length < 2) { + if (args.length < 2) {
+ this.b = 0; + return 0;
+ return;
+ } + }
+ +
+ EntityPlayer[] players = ((java.util.List<EntityPlayer>)PlayerSelector.getPlayers(this, args[1], EntityPlayer.class)).toArray(new EntityPlayer[0]); + EntityPlayer[] players = ((java.util.List<EntityPlayer>) PlayerSelector.getPlayers(sender, args[1], EntityPlayer.class)).toArray(new EntityPlayer[0]);
+ +
+ if (players != null && players.length > 0) { + if (players != null && players.length > 0) {
+ this.b = players.length; + return players.length;
+ return;
+ } else { + } else {
+ EntityPlayer player = MinecraftServer.getServer().getPlayerList().getPlayer(args[1]); + EntityPlayer player = MinecraftServer.getServer().getPlayerList().getPlayer(args[1]);
+ if (player == null) { + if (player == null) {
+ this.b = 0; + return 0;
+ return;
+ } else { + } else {
+ this.b = 1; + return 1;
+ return;
+ } + }
+ } + }
+ } + }
@ -99,7 +104,7 @@
+ for (int i = 0; i < args.length; i++) { + for (int i = 0; i < args.length; i++) {
+ if (PlayerSelector.isPattern(args[i])) { + if (PlayerSelector.isPattern(args[i])) {
+ for (int j = 0; j < commands.size(); j++) { + for (int j = 0; j < commands.size(); j++) {
+ newCommands.addAll(this.buildCommands(commands.get(j), i)); + newCommands.addAll(buildCommands(sender, commands.get(j), i));
+ } + }
+ ArrayList<String[]> temp = commands; + ArrayList<String[]> temp = commands;
+ commands = newCommands; + commands = newCommands;
@ -113,15 +118,15 @@
+ // Now dispatch all of the commands we ended up with + // Now dispatch all of the commands we ended up with
+ for (int i = 0; i < commands.size(); i++) { + for (int i = 0; i < commands.size(); i++) {
+ try { + try {
+ if (commandMap.dispatch(sender, joiner.join(java.util.Arrays.asList(commands.get(i))))) { + if (commandMap.dispatch(bSender, joiner.join(java.util.Arrays.asList(commands.get(i))))) {
+ completed++; + completed++;
+ } + }
+ } catch (Throwable exception) { + } catch (Throwable exception) {
+ if(this instanceof TileEntityCommandListener) { + if (sender instanceof TileEntityCommandListener) {
+ TileEntityCommandListener listener = (TileEntityCommandListener) this; + TileEntityCommandListener listener = (TileEntityCommandListener) sender;
+ MinecraftServer.getLogger().log(Level.WARN, String.format("CommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().getX(), listener.getChunkCoordinates().getY(), listener.getChunkCoordinates().getZ()), exception); + MinecraftServer.getLogger().log(Level.WARN, String.format("CommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().getX(), listener.getChunkCoordinates().getY(), listener.getChunkCoordinates().getZ()), exception);
+ } else if (this instanceof EntityMinecartCommandBlockListener) { + } else if (sender instanceof EntityMinecartCommandBlockListener) {
+ EntityMinecartCommandBlockListener listener = (EntityMinecartCommandBlockListener) this; + EntityMinecartCommandBlockListener listener = (EntityMinecartCommandBlockListener) sender;
+ MinecraftServer.getLogger().log(Level.WARN, String.format("MinecartCommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().getX(), listener.getChunkCoordinates().getY(), listener.getChunkCoordinates().getZ()), exception); + MinecraftServer.getLogger().log(Level.WARN, String.format("MinecartCommandBlock at (%d,%d,%d) failed to handle command", listener.getChunkCoordinates().getX(), listener.getChunkCoordinates().getY(), listener.getChunkCoordinates().getZ()), exception);
+ } else { + } else {
+ MinecraftServer.getLogger().log(Level.WARN, String.format("Unknown CommandBlock failed to handle command"), exception); + MinecraftServer.getLogger().log(Level.WARN, String.format("Unknown CommandBlock failed to handle command"), exception);
@ -129,25 +134,16 @@
+ } + }
+ } + }
+ +
+ this.b = completed; + return completed;
+ // CraftBukkit end
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Executing command block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Command to be executed");
@@ -91,8 +202,27 @@
} else {
this.b = 0;
}
+ } + }
+ +
+ // CraftBukkit start + private static ArrayList<String[]> buildCommands(ICommandListener sender, String[] args, int pos) {
+ private ArrayList<String[]> buildCommands(String[] args, int pos) {
+ ArrayList<String[]> commands = new ArrayList<String[]>(); + ArrayList<String[]> commands = new ArrayList<String[]>();
+ java.util.List<EntityPlayer> players = (java.util.List<EntityPlayer>)PlayerSelector.getPlayers(this, args[pos], EntityPlayer.class); + java.util.List<EntityPlayer> players = (java.util.List<EntityPlayer>)PlayerSelector.getPlayers(sender, args[pos], EntityPlayer.class);
+ +
+ if (players != null) { + if (players != null) {
+ for (EntityPlayer player : players) { + for (EntityPlayer player : players) {
+ if (player.world != this.getWorld()) { + if (player.world != sender.getWorld()) {
+ continue; + continue;
+ } + }
+ String[] command = args.clone(); + String[] command = args.clone();

Datei anzeigen

@ -1,5 +1,5 @@
--- ../work/decompile-8eb82bde//net/minecraft/server/TileEntitySign.java 2014-11-30 11:23:30.317220028 +0000 --- ../work/decompile-8eb82bde//net/minecraft/server/TileEntitySign.java 2014-12-05 23:10:25.877614213 +0000
+++ src/main/java/net/minecraft/server/TileEntitySign.java 2014-11-30 11:22:37.521221199 +0000 +++ src/main/java/net/minecraft/server/TileEntitySign.java 2014-12-05 23:06:56.609618857 +0000
@@ -20,6 +20,12 @@ @@ -20,6 +20,12 @@
nbttagcompound.setString("Text" + (i + 1), s); nbttagcompound.setString("Text" + (i + 1), s);
@ -41,3 +41,15 @@
} catch (CommandException commandexception) { } catch (CommandException commandexception) {
this.lines[i] = ichatbasecomponent; this.lines[i] = ichatbasecomponent;
} }
@@ -77,7 +96,10 @@
ChatClickable chatclickable = chatmodifier.h();
if (chatclickable.a() == EnumClickAction.RUN_COMMAND) {
- MinecraftServer.getServer().getCommandHandler().a(tileentitysignplayerwrapper, chatclickable.b());
+ // CraftBukkit start
+ // MinecraftServer.getServer().getCommandHandler().a(tileentitysignplayerwrapper, chatclickable.b());
+ CommandBlockListenerAbstract.executeCommand(tileentitysignplayerwrapper, (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), chatclickable.b());
+ // CraftBukkit ebd
}
}
}

Datei anzeigen

@ -70,7 +70,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0)); return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0));
} }
public final int dispatchVanillaCommandBlock(CommandBlockListenerAbstract icommandlistener, String s) { public final int dispatchVanillaCommandBlock(ICommandListener icommandlistener, String s) {
// Copied from net.minecraft.server.CommandHandler // Copied from net.minecraft.server.CommandHandler
s = s.trim(); s = s.trim();
if (s.startsWith("/")) { if (s.startsWith("/")) {