From 7cddc13d289484125b56e567e3ea5c0771be3f1e Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 24 Sep 2011 23:14:13 +0100 Subject: [PATCH] Blocked access to ColouredConsoleSenders constructor, implemented getConsoleSender By: Dinnerbone --- .../main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++++ .../craftbukkit/command/ColouredConsoleSender.java | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 9129b58e6f..482405c9af 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -839,4 +839,8 @@ public final class CraftServer implements Server { ((CraftWorld)world).getHandle().worldData.setGameType(mode.getValue()); } } + + public ConsoleCommandSender getConsoleSender() { + return console.console; + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java index 4dabe6f03f..28f252e11a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java @@ -5,6 +5,7 @@ import java.util.Map; import jline.ANSIBuffer.ANSICodes; import jline.ConsoleReader; import jline.Terminal; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.craftbukkit.CraftServer; @@ -15,7 +16,7 @@ public class ColouredConsoleSender extends ConsoleCommandSender { private final Map replacements = new EnumMap(ChatColor.class); private final ChatColor[] colors = ChatColor.values(); - public ColouredConsoleSender(CraftServer server) { + protected ColouredConsoleSender(CraftServer server) { super(server); this.reader = server.getReader(); this.terminal = reader.getTerminal(); @@ -55,4 +56,12 @@ public class ColouredConsoleSender extends ConsoleCommandSender { super.sendMessage(message); } } + + public static ConsoleCommandSender getInstance() { + if (Bukkit.getConsoleSender() != null) { + return Bukkit.getConsoleSender(); + } else { + return new ColouredConsoleSender((CraftServer)Bukkit.getServer()); + } + } }