diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-10-31 06:36:55 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-10-31 06:37:46 -0500 |
commit | 46d7cd1e0502edbbca323b2a289a49fbf951628d (patch) | |
tree | 095034bea876ce241ed3c2f401903071069bb913 /src | |
parent | 9e4e2c62af6b6d12cc6a15cbf117d0a7586372c6 (diff) | |
download | craftbukkit-46d7cd1e0502edbbca323b2a289a49fbf951628d.tar craftbukkit-46d7cd1e0502edbbca323b2a289a49fbf951628d.tar.gz craftbukkit-46d7cd1e0502edbbca323b2a289a49fbf951628d.tar.lz craftbukkit-46d7cd1e0502edbbca323b2a289a49fbf951628d.tar.xz craftbukkit-46d7cd1e0502edbbca323b2a289a49fbf951628d.zip |
Use BlockCommandSender for dispatching Command block commands
Also allow commands that don't start with a / to match vanilla behavior
Diffstat (limited to 'src')
3 files changed, 55 insertions, 10 deletions
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java index 87d5cd26..b763b482 100644 --- a/src/main/java/net/minecraft/server/TileEntity.java +++ b/src/main/java/net/minecraft/server/TileEntity.java @@ -9,7 +9,7 @@ public class TileEntity { private static Map a = new HashMap(); private static Map b = new HashMap(); - protected World world; + public World world; // CraftBukkit - protected -> public public int x; public int y; public int z; diff --git a/src/main/java/net/minecraft/server/TileEntityCommand.java b/src/main/java/net/minecraft/server/TileEntityCommand.java index 1a8317a4..78e462a3 100644 --- a/src/main/java/net/minecraft/server/TileEntityCommand.java +++ b/src/main/java/net/minecraft/server/TileEntityCommand.java @@ -9,8 +9,11 @@ import com.google.common.base.Joiner; public class TileEntityCommand extends TileEntity implements ICommandListener { private String a = ""; + private final org.bukkit.command.BlockCommandSender sender; - public TileEntityCommand() {} + public TileEntityCommand() { + sender = new org.bukkit.craftbukkit.command.CraftBlockCommandSender(this); + } public void b(String s) { this.a = s; @@ -23,15 +26,12 @@ public class TileEntityCommand extends TileEntity implements ICommandListener { if (minecraftserver != null && minecraftserver.getEnableCommandBlock()) { // 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 command = this.a; + if (this.a.startsWith("/")) { + command = this.a.substring(1); + } String[] args = command.split(" "); ArrayList<String[]> commands = new ArrayList<String[]>(); @@ -50,13 +50,16 @@ public class TileEntityCommand extends TileEntity implements ICommandListener { commands.add(args); // find positions of command block syntax, if any + ArrayList<String[]> newCommands = new ArrayList<String[]>(); 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)); } + ArrayList<String[]> temp = commands; commands = newCommands; + newCommands = temp; + newCommands.clear(); } } diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java new file mode 100644 index 00000000..89be6326 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java @@ -0,0 +1,42 @@ +package org.bukkit.craftbukkit.command; + +import net.minecraft.server.TileEntityCommand; +import org.bukkit.block.Block; +import org.bukkit.command.BlockCommandSender; + +/** + * Represents input from a command block + */ +public class CraftBlockCommandSender extends ServerCommandSender implements BlockCommandSender { + private final TileEntityCommand commandBlock; + + public CraftBlockCommandSender(TileEntityCommand commandBlock) { + super(); + this.commandBlock = commandBlock; + } + + public Block getBlock() { + return commandBlock.world.getWorld().getBlockAt(commandBlock.x, commandBlock.y, commandBlock.z); + } + + public void sendMessage(String message) { + } + + public void sendRawMessage(String message) { + } + + public void sendMessage(String[] messages) { + } + + public String getName() { + return "@"; + } + + public boolean isOp() { + return true; + } + + public void setOp(boolean value) { + throw new UnsupportedOperationException("Cannot change operator status of a block"); + } +} |