diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java index 87d5cd26a9..b763b482e4 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 1a8317a485..78e462a360 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 commands = new ArrayList(); @@ -50,13 +50,16 @@ public class TileEntityCommand extends TileEntity implements ICommandListener { commands.add(args); // find positions of command block syntax, if any + ArrayList newCommands = new ArrayList(); for (int i = 0; i < args.length; i++) { if (PlayerSelector.isPattern(args[i])) { - ArrayList newCommands = new ArrayList(); for (int j = 0; j < commands.size(); j++) { newCommands.addAll(this.buildCommands(commands.get(j), i)); } + ArrayList 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 0000000000..89be6326f0 --- /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"); + } +}