3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00

Use BlockCommandSender for dispatching Command block commands

Also allow commands that don't start with a / to match vanilla behavior
Dieser Commit ist enthalten in:
Travis Watkins 2012-10-31 06:36:55 -05:00
Ursprung 9e4e2c62af
Commit 46d7cd1e05
3 geänderte Dateien mit 55 neuen und 10 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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");
}
}