Implement new interface ConsoleCommandSender.

Also use abstracted ServerCommandSender to reduce complexity! Yay!
This commit is contained in:
Andrew Ardill 2011-12-07 17:04:00 +11:00
parent 93a4a9ba8c
commit 4e318dd1c8
3 changed files with 37 additions and 5 deletions

View file

@ -1,6 +1,8 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import org.bukkit.craftbukkit.command.CraftConsoleCommandSender;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import com.avaje.ebean.config.DataSourceConfig; import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.config.ServerConfig;

View file

@ -10,15 +10,15 @@ import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
public class ColouredConsoleSender extends ConsoleCommandSender { public class ColouredConsoleSender extends CraftConsoleCommandSender {
private final ConsoleReader reader; private final ConsoleReader reader;
private final Terminal terminal; private final Terminal terminal;
private final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class); private final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class);
private final ChatColor[] colors = ChatColor.values(); private final ChatColor[] colors = ChatColor.values();
protected ColouredConsoleSender(CraftServer server) { protected ColouredConsoleSender() {
super(server); super();
this.reader = server.getReader(); this.reader = ((CraftServer) getServer()).getReader();
this.terminal = reader.getTerminal(); this.terminal = reader.getTerminal();
replacements.put(ChatColor.BLACK, ANSICodes.attrib(0)); replacements.put(ChatColor.BLACK, ANSICodes.attrib(0));
@ -61,7 +61,7 @@ public class ColouredConsoleSender extends ConsoleCommandSender {
if (Bukkit.getConsoleSender() != null) { if (Bukkit.getConsoleSender() != null) {
return Bukkit.getConsoleSender(); return Bukkit.getConsoleSender();
} else { } else {
return new ColouredConsoleSender((CraftServer)Bukkit.getServer()); return new ColouredConsoleSender();
} }
} }
} }

View file

@ -0,0 +1,30 @@
package org.bukkit.craftbukkit.command;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
/**
* Represents CLI input from a console
*/
public class CraftConsoleCommandSender extends ServerCommandSender implements ConsoleCommandSender {
protected CraftConsoleCommandSender() {
super();
}
public void sendMessage(String message) {
System.out.println(ChatColor.stripColor(message));
}
public String getName() {
return "CONSOLE";
}
public boolean isOp() {
return true;
}
public void setOp(boolean value) {
throw new UnsupportedOperationException("Cannot change operator status of server console");
}
}