From 5ec39c35815cb0d3a16849082b85f9c8b2b6d796 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 14 Nov 2016 17:58:09 +0100 Subject: [PATCH] Fixed flair in onGetInfo, improved channels --- .../java/buttondevteam/chat/ChatPlayer.java | 25 +++++- .../chat/listener/PlayerListener.java | 81 ++++++------------- 2 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatPlayer.java b/src/main/java/buttondevteam/chat/ChatPlayer.java index 5c45007..806c1d1 100644 --- a/src/main/java/buttondevteam/chat/ChatPlayer.java +++ b/src/main/java/buttondevteam/chat/ChatPlayer.java @@ -81,14 +81,31 @@ public class ChatPlayer extends TBMCPlayer { public static final short FlairTimeCantPress = -2; public static final short FlairTimeNone = -3; - public String GetFormattedFlair() { + /** + * Gets the player's flair, optionally formatting for Minecraft. + * + * @param noformats + * The MC formatting codes will be only applied if false + * @return The flair + */ + public String GetFormattedFlair(boolean noformats) { if (getFlairTime() == FlairTimeCantPress) - return String.format("§r(--s)§r"); + return String.format(noformats ? "(can't press)" : "§r(--s)§r"); if (getFlairTime() == FlairTimeNonPresser) - return String.format("§7(--s)§r"); + return String.format(noformats ? "(non-presser)" : "§7(--s)§r"); if (getFlairTime() == FlairTimeNone) return ""; - return String.format("§%x(%ss)§r", GetFlairColor(), getFlairTime()); + return noformats ? String.format("(%ss)", getFlairTime()) + : String.format("§%x(%ss)§r", GetFlairColor(), getFlairTime()); + } + + /** + * Gets the player's flair, formatted for Minecraft. + * + * @return The flair + */ + public String GetFormattedFlair() { + return GetFormattedFlair(false); } public void SetFlair(short time) { diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 982d646..ee323b2 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -321,62 +321,28 @@ public class PlayerListener implements Listener { String cmd = ""; if (index == -1) { cmd = event.getCommand(); - if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) { - ConsoleChannel = Channel.GlobalChat; - event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName); - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) { - if (ConsoleChannel.equals(Channel.AdminChat)) - ConsoleChannel = Channel.GlobalChat; - else - ConsoleChannel = Channel.AdminChat; - event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName); - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) { - if (ConsoleChannel.equals(Channel.ModChat)) - ConsoleChannel = Channel.GlobalChat; - else - ConsoleChannel = Channel.ModChat; - event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName); - event.setCommand("dontrunthiscmd"); + for (Channel channel : Channel.getChannels()) { + if (cmd.equalsIgnoreCase(channel.Command)) { + if (ConsoleChannel.equals(channel)) + ConsoleChannel = Channel.GlobalChat; + else + ConsoleChannel = channel; + event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName); + event.setCommand("dontrunthiscmd"); + break; + } } } else { cmd = event.getCommand().substring(0, index); - if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) { - Channel c = ConsoleChannel; - ConsoleChannel = Channel.GlobalChat; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), - event.getCommand().substring(index + 1)); - ConsoleChannel = c; - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) { - Channel c = ConsoleChannel; - ConsoleChannel = Channel.TownChat; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), - event.getCommand().substring(index + 1)); - ConsoleChannel = c; - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) { - Channel c = ConsoleChannel; - ConsoleChannel = Channel.NationChat; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), - event.getCommand().substring(index + 1)); - ConsoleChannel = c; - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) { - Channel c = ConsoleChannel; - ConsoleChannel = Channel.AdminChat; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), - event.getCommand().substring(index + 1)); - ConsoleChannel = c; - event.setCommand("dontrunthiscmd"); - } else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) { - Channel c = ConsoleChannel; - ConsoleChannel = Channel.ModChat; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), - event.getCommand().substring(index + 1)); - ConsoleChannel = c; - event.setCommand("dontrunthiscmd"); + for (Channel channel : Channel.getChannels()) { + if (cmd.equalsIgnoreCase(channel.Command)) { + Channel c = ConsoleChannel; + ConsoleChannel = channel; + ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), + event.getCommand().substring(index + 1)); + ConsoleChannel = c; + event.setCommand("dontrunthiscmd"); + } } } if (cmd.toLowerCase().startsWith("un")) { @@ -409,8 +375,11 @@ public class PlayerListener implements Listener { e.addInfo("Reddit name: " + cp.getUserName()); if (e.getTarget() == InfoTarget.MCCommand) e.addInfo("/r/TheButton flair: " + cp.GetFormattedFlair()); - else - e.addInfo("/r/TheButton flair: (" + cp.getFlairTime() + "s)"); - e.addInfo("Respect: " + cp.getFCount() / cp.getFDeaths()); + else { + final String flair = cp.GetFormattedFlair(true); + if (flair.length() > 0) + e.addInfo("/r/TheButton flair: " + flair); + } + e.addInfo("Respect: " + (double) cp.getFCount() / (double) cp.getFDeaths()); } }