From 4e318dd1c8e7b6b1cf741f9966a76fadc2f3ef1a Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Wed, 7 Dec 2011 17:04:00 +1100 Subject: [PATCH] Implement new interface ConsoleCommandSender. Also use abstracted ServerCommandSender to reduce complexity! Yay! --- .../org/bukkit/craftbukkit/CraftServer.java | 2 ++ .../command/ColouredConsoleSender.java | 10 +++---- .../command/CraftConsoleCommandSender.java | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 45d74964aa..a70d1b3d07 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1,6 +1,8 @@ package org.bukkit.craftbukkit; import java.io.FileNotFoundException; + +import org.bukkit.craftbukkit.command.CraftConsoleCommandSender; import org.bukkit.generator.ChunkGenerator; import com.avaje.ebean.config.DataSourceConfig; import com.avaje.ebean.config.ServerConfig; diff --git a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java index 28f252e11a..f1deb305c9 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java +++ b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java @@ -10,15 +10,15 @@ import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.craftbukkit.CraftServer; -public class ColouredConsoleSender extends ConsoleCommandSender { +public class ColouredConsoleSender extends CraftConsoleCommandSender { private final ConsoleReader reader; private final Terminal terminal; private final Map replacements = new EnumMap(ChatColor.class); private final ChatColor[] colors = ChatColor.values(); - protected ColouredConsoleSender(CraftServer server) { - super(server); - this.reader = server.getReader(); + protected ColouredConsoleSender() { + super(); + this.reader = ((CraftServer) getServer()).getReader(); this.terminal = reader.getTerminal(); replacements.put(ChatColor.BLACK, ANSICodes.attrib(0)); @@ -61,7 +61,7 @@ public class ColouredConsoleSender extends ConsoleCommandSender { if (Bukkit.getConsoleSender() != null) { return Bukkit.getConsoleSender(); } else { - return new ColouredConsoleSender((CraftServer)Bukkit.getServer()); + return new ColouredConsoleSender(); } } } diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java new file mode 100644 index 0000000000..2f9879ff43 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java @@ -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"); + } +}