diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-10-30 23:29:14 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-10-31 02:39:56 -0500 |
commit | 59dc403a61e4aec5f127fbbc7e1a5a66970f97f1 (patch) | |
tree | 741bb356ee2500c28ccc830552861321017d5027 /src | |
parent | 63eaf74d44aef155b90cce2d25d9be96b4249702 (diff) | |
download | craftbukkit-59dc403a61e4aec5f127fbbc7e1a5a66970f97f1.tar craftbukkit-59dc403a61e4aec5f127fbbc7e1a5a66970f97f1.tar.gz craftbukkit-59dc403a61e4aec5f127fbbc7e1a5a66970f97f1.tar.lz craftbukkit-59dc403a61e4aec5f127fbbc7e1a5a66970f97f1.tar.xz craftbukkit-59dc403a61e4aec5f127fbbc7e1a5a66970f97f1.zip |
Hook command block up to ConsoleCommandSender. Fixes BUKKIT-2684
This will need to have its own CommandSender but this makes command blocks
work for now with any command console can run.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/TileEntityCommand.java | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/src/main/java/net/minecraft/server/TileEntityCommand.java b/src/main/java/net/minecraft/server/TileEntityCommand.java index d9a04fae..1a8317a4 100644 --- a/src/main/java/net/minecraft/server/TileEntityCommand.java +++ b/src/main/java/net/minecraft/server/TileEntityCommand.java @@ -1,5 +1,11 @@ package net.minecraft.server; +// CraftBukkit start +import java.util.ArrayList; +import java.util.Arrays; +import com.google.common.base.Joiner; +// CraftBukkit end + public class TileEntityCommand extends TileEntity implements ICommandListener { private String a = ""; @@ -16,15 +22,69 @@ public class TileEntityCommand extends TileEntity implements ICommandListener { MinecraftServer minecraftserver = MinecraftServer.getServer(); if (minecraftserver != null && minecraftserver.getEnableCommandBlock()) { - // CraftBukkit start - disable command block TODO: hook this up to bukkit API - // ICommandHandler icommandhandler = minecraftserver.getCommandHandler(); - - // icommandhandler.a(this, this.a); + // CraftBukkit start - handle command block as console TODO: add new CommandSender for this + // Commands in command block must start with / + if (!this.a.startsWith("/")) { + return; + } + + org.bukkit.command.SimpleCommandMap commandMap = minecraftserver.server.getCommandMap(); + org.bukkit.command.ConsoleCommandSender sender = minecraftserver.server.getConsoleSender(); + Joiner joiner = Joiner.on(" "); + String command = this.a.substring(1); + String[] args = command.split(" "); + ArrayList<String[]> commands = new ArrayList<String[]>(); + + // block disallowed commands + 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("pardon") || args[0].equalsIgnoreCase("pardon-ip") || args[0].equalsIgnoreCase("reload")) { + return; + } + + // make sure this is a valid command + if (commandMap.getCommand(args[0]) == null) { + return; + } + + commands.add(args); + + // find positions of command block syntax, if any + for (int i = 0; i < args.length; i++) { + if (PlayerSelector.isPattern(args[i])) { + ArrayList<String[]> newCommands = new ArrayList<String[]>(); + for (int j = 0; j < commands.size(); j++) { + newCommands.addAll(this.buildCommands(commands.get(j), i)); + } + commands = newCommands; + } + } + + // now dispatch all of the commands we ended up with + for (int i = 0; i < commands.size(); i++) { + commandMap.dispatch(sender, joiner.join(Arrays.asList(commands.get(i)))); + } // CraftBukkit end } } } + // CraftBukkit start + private ArrayList<String[]> buildCommands(String[] args, int pos) { + ArrayList<String[]> commands = new ArrayList<String[]>(); + EntityPlayer[] players = PlayerSelector.getPlayers(this, args[pos]); + if (players != null) { + for (EntityPlayer player : players) { + String[] command = args.clone(); + command[pos] = player.getLocalizedName(); + commands.add(command); + } + } + + return commands; + } + // CraftBukkit end + public String getName() { return "@"; } |