From 8dc253564c7cca228decc13b5e35e05fb34e9676 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 21 Apr 2016 21:46:28 +0200 Subject: [PATCH] Done #12 - Changed color setting --- .../thebuttonautoflair/ChatProcessing.java | 117 ++++++++---------- src/tk/sznp/thebuttonautoflair/Commands.java | 11 +- .../MaybeOfflinePlayer.java | 2 +- 3 files changed, 59 insertions(+), 71 deletions(-) diff --git a/src/tk/sznp/thebuttonautoflair/ChatProcessing.java b/src/tk/sznp/thebuttonautoflair/ChatProcessing.java index c780ae2..64fc184 100644 --- a/src/tk/sznp/thebuttonautoflair/ChatProcessing.java +++ b/src/tk/sznp/thebuttonautoflair/ChatProcessing.java @@ -26,19 +26,20 @@ public class ChatProcessing { PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager() .getPlugin("Essentials")); Player player = (sender instanceof Player ? (Player) sender : null); - if (player != null && message.equalsIgnoreCase("F")) { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(player - .getUniqueId()); - if (!mp.PressedF && PlayerListener.ActiveF) { - PlayerListener.FCount++; - mp.PressedF = true; - if (PlayerListener.FPlayer != null - && PlayerListener.FPlayer.FCount < Integer.MAX_VALUE - 1) - PlayerListener.FPlayer.FCount++; + MaybeOfflinePlayer mp = null; + if (player != null) { + mp = MaybeOfflinePlayer.AllPlayers.get(player.getUniqueId()); + if (message.equalsIgnoreCase("F")) { + if (!mp.PressedF && PlayerListener.ActiveF) { + PlayerListener.FCount++; + mp.PressedF = true; + if (PlayerListener.FPlayer != null + && PlayerListener.FPlayer.FCount < Integer.MAX_VALUE - 1) + PlayerListener.FPlayer.FCount++; + } } } - boolean greentext = message.startsWith(">"); String msg = message.toLowerCase(); if (player != null && msg.contains("lol")) { Commands.Lastlol = MaybeOfflinePlayer.AllPlayers.get(player @@ -54,13 +55,16 @@ public class ChatProcessing { } } } + Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel + : mp.CurrentChannel); + + String colormode = currentchannel.Color; + if (mp.OtherColorMode.length() > 0) + colormode = mp.OtherColorMode; + if (message.startsWith(">")) + colormode = "green"; // If greentext, ignore channel or player + // colors - MaybeOfflinePlayer mplayer = null; - if (player != null) { - mplayer = MaybeOfflinePlayer.AllPlayers.get(player.getUniqueId()); - } - Channel currentchannel = (mplayer == null ? PlayerListener.ConsoleChannel - : mplayer.CurrentChannel); String formattedmessage = message; formattedmessage = formattedmessage.replace("\\", "\\\\"); // It's // really @@ -91,17 +95,14 @@ public class ChatProcessing { item, String.format( "\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"", - (greentext ? "green" - : currentchannel.Color), url, - (greentext ? "green" - : currentchannel.Color), url)); + colormode, url, colormode, url)); hadurls = true; } catch (MalformedURLException e) { } - if (mplayer != null && mplayer.RainbowPresserColorMode) { // TODO: - // Rainbow - // mode - // for + if (mp != null && mp.RainbowPresserColorMode) { // TODO: + // Rainbow + // mode + // for // console if (item.startsWith(RainbowPresserColors[rpc])) { // Prevent // words @@ -129,10 +130,6 @@ public class ChatProcessing { } currentindex += item.length() + 3; } - if (mplayer != null && mplayer.OtherColorMode != 0xFF) { - formattedmessage = String.format("§%x%s", mplayer.OtherColorMode, - formattedmessage); - } if (!hadurls) { for (Player p : PluginMain.GetPlayers()) { @@ -140,27 +137,24 @@ public class ChatProcessing { if (formattedmessage.matches("(?i).*" + Pattern.quote(p.getName()) + ".*")) { if (PlayerListener.NotificationSound == null) - p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, - 0.5f); + p.playSound(p.getLocation(), + Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: + // Airhorn else p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f, (float) PlayerListener.NotificationPitch); - MaybeOfflinePlayer mp = MaybeOfflinePlayer + MaybeOfflinePlayer mpp = MaybeOfflinePlayer .AddPlayerIfNeeded(p.getUniqueId()); color = String.format( "§%x", - (mp.GetFlairColor() == 0x00 ? 0xb : mp + (mpp.GetFlairColor() == 0x00 ? 0xb : mpp .GetFlairColor())); } formattedmessage = formattedmessage.replaceAll( "(?i)" + Pattern.quote(p.getName()), - color - + p.getName() - + (greentext ? "§a" - : currentchannel.DisplayName.substring( - 0, 2))); + color + p.getName() + "§r"); } for (String n : PlayerListener.nicknames.keySet()) { Player p = null; @@ -180,8 +174,8 @@ public class ChatProcessing { + Pattern.quote(nwithoutformatting) + ".*")) { p = Bukkit.getPlayer(PlayerListener.nicknames.get(n)); if (PlayerListener.NotificationSound == null) - p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, - 0.5f); // 2015.08.12. + p.playSound(p.getLocation(), + Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // 2015.08.12. else p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f, @@ -189,12 +183,8 @@ public class ChatProcessing { MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); } if (p != null) { - formattedmessage = formattedmessage.replaceAll( - "(?i)" + Pattern.quote(nwithoutformatting), - n - + (greentext ? "§a" - : currentchannel.DisplayName - .substring(0, 2))); + formattedmessage = formattedmessage.replaceAll("(?i)" + + Pattern.quote(nwithoutformatting), n + "§r"); } } @@ -214,29 +204,28 @@ public class ChatProcessing { json.append("[\"\","); json.append(String .format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"%s\"}},", - currentchannel.DisplayName, (mplayer != null - && !mplayer.RPMode ? "[OOC]" : ""), suggestmsg)); + currentchannel.DisplayName, + (mp != null && !mp.RPMode ? "[OOC]" : ""), suggestmsg)); json.append("{\"text\":\" <\"},"); json.append(String.format("{\"text\":\"%s%s\",", (player != null ? player.getDisplayName() : sender.getName()), - (mplayer != null ? mplayer.GetFormattedFlair() : ""))); + (mp != null ? mp.GetFormattedFlair() : ""))); json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["); json.append(String.format("{\"text\":\"%s\n\",", (player != null ? player.getName() : sender.getName()))); json.append(String .format("\"color\":\"aqua\"},{\"text\":\"World: %s\n\",\"color\":\"white\"},", (player != null ? player.getWorld().getName() : "-"))); - json.append(String.format( - "{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},", - (mplayer != null ? (mplayer.FCount / (double) mplayer.FDeaths) - : "Infinite"), - (mplayer != null && mplayer.UserName != null - && !mplayer.UserName.isEmpty() ? "\nUserName: " - + mplayer.UserName : ""), - (mplayer != null - && mplayer.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: " - + PlayerListener.AlphaDeaths - : ""))); + json.append(String + .format("{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},", + (mp != null ? (mp.FCount / (double) mp.FDeaths) + : "Infinite"), + (mp != null && mp.UserName != null + && !mp.UserName.isEmpty() ? "\nUserName: " + + mp.UserName : ""), + (mp != null && mp.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: " + + PlayerListener.AlphaDeaths + : ""))); json.append("{\"text\":\"> \",\"color\":\"white\"},"); int index = -1; @@ -261,13 +250,11 @@ public class ChatProcessing { "#" + original, String.format( "\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"", - (greentext ? "green" - : currentchannel.Color), - original, original)); + colormode, original, original)); } json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]", - formattedmessage, (greentext ? "green" : currentchannel.Color))); + formattedmessage, colormode)); String jsonstr = json.toString(); if (jsonstr.length() >= 32767) { sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting."); @@ -460,8 +447,8 @@ public class ChatProcessing { currentchannel.DisplayName, (player != null ? player.getDisplayName() : sender.getName()), - (mplayer != null ? mplayer.GetFormattedFlair() - : ""), message)); + (mp != null ? mp.GetFormattedFlair() : ""), + message)); return true; } } diff --git a/src/tk/sznp/thebuttonautoflair/Commands.java b/src/tk/sznp/thebuttonautoflair/Commands.java index e241b38..8b09e69 100644 --- a/src/tk/sznp/thebuttonautoflair/Commands.java +++ b/src/tk/sznp/thebuttonautoflair/Commands.java @@ -93,6 +93,7 @@ public class Commands implements CommandExecutor { Timer timer = new Timer(); PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { Player player = Bukkit.getPlayer(mp.UUID); + @Override public void run() { try { @@ -187,7 +188,7 @@ public class Commands implements CommandExecutor { if (args.length < 2) { if (PluginMain.permission.has(player, "tbmc.rainbow")) { p.RainbowPresserColorMode = !p.RainbowPresserColorMode; - p.OtherColorMode = 0xFF; + p.OtherColorMode = ""; if (p.RainbowPresserColorMode) player.sendMessage("§eRainbow colors §aenabled."); else @@ -199,11 +200,11 @@ public class Commands implements CommandExecutor { } else { if (PluginMain.permission.has(player, "tbmc.admin")) { p.RainbowPresserColorMode = false; - p.OtherColorMode = Short.parseShort(args[1], 16); - if (p.OtherColorMode != 0xFF) + p.OtherColorMode = args[1]; + if (p.OtherColorMode.length() > 0) player.sendMessage(String.format( - "§eMessage color set to §%x%x", - p.OtherColorMode, p.OtherColorMode)); + "§eMessage color set to %s", + p.OtherColorMode)); else player.sendMessage("§eMessage color reset."); } else { diff --git a/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java b/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java index a60fead..5a58d8a 100644 --- a/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java +++ b/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java @@ -28,7 +28,7 @@ public class MaybeOfflinePlayer { public boolean SendingLink = false; public int FDeaths; public boolean RainbowPresserColorMode = false; - public short OtherColorMode = 0xFF; + public String OtherColorMode = ""; public UUID UUID;