From b797749442bc5eb3473affa12839e4b998f248a1 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Tue, 28 Apr 2020 20:36:48 +0800 Subject: [PATCH] 2.1.1 Update --- .../loohp/interactivechat/ConfigManager.java | 2 ++ .../interactivechat/InteractiveChat.java | 2 ++ .../Utils/ChatColorFilter.java | 2 +- .../Utils/CustomStringUtils.java | 24 ++++++++++--------- src/config.yml | 2 ++ src/plugin.yml | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/com/loohp/interactivechat/ConfigManager.java b/src/com/loohp/interactivechat/ConfigManager.java index 96d101ef..febf96d8 100644 --- a/src/com/loohp/interactivechat/ConfigManager.java +++ b/src/com/loohp/interactivechat/ConfigManager.java @@ -26,6 +26,8 @@ public static void reloadConfig() { } public static void loadConfig() { + InteractiveChat.FilterUselessColorCodes = getConfig().getBoolean("Settings.FilterUselessColorCodes"); + InteractiveChat.AllowMention = getConfig().getBoolean("Chat.AllowMention"); InteractiveChat.NoPermission = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Messages.NoPermission")); diff --git a/src/com/loohp/interactivechat/InteractiveChat.java b/src/com/loohp/interactivechat/InteractiveChat.java index efc2e9c7..187d0cc1 100644 --- a/src/com/loohp/interactivechat/InteractiveChat.java +++ b/src/com/loohp/interactivechat/InteractiveChat.java @@ -115,6 +115,8 @@ public class InteractiveChat extends JavaPlugin { public static int UpdaterTaskID = -1; public static HashMap essenNick = new HashMap(); + + public static boolean FilterUselessColorCodes = true; @Override public void onEnable() { diff --git a/src/com/loohp/interactivechat/Utils/ChatColorFilter.java b/src/com/loohp/interactivechat/Utils/ChatColorFilter.java index ebc51df8..438e6d2a 100644 --- a/src/com/loohp/interactivechat/Utils/ChatColorFilter.java +++ b/src/com/loohp/interactivechat/Utils/ChatColorFilter.java @@ -3,7 +3,7 @@ public class ChatColorFilter { public static String removeUselessColorCodes(String string) { - return string.replaceAll("(§[0-9,a-f]){2,}", ""); + return string.replaceAll("^(§[0-9,a-f,l-o,r])*(?=§[0-9,a-f,r])", ""); } public static String filterIllegalColorCodes(String string) { diff --git a/src/com/loohp/interactivechat/Utils/CustomStringUtils.java b/src/com/loohp/interactivechat/Utils/CustomStringUtils.java index 191d4a6f..5fc1c7c9 100644 --- a/src/com/loohp/interactivechat/Utils/CustomStringUtils.java +++ b/src/com/loohp/interactivechat/Utils/CustomStringUtils.java @@ -108,17 +108,19 @@ public static List loadExtras(List baseComp) { } } - Iterator itr = list.iterator(); - while (itr.hasNext()) { - BaseComponent base = itr.next(); - if (base instanceof TextComponent) { - TextComponent text = (TextComponent) base; - if (text.getText().matches("§.")) { - itr.remove(); - } else { - text.setText(ChatColorFilter.removeUselessColorCodes(text.getText())); - } - } + if (InteractiveChat.FilterUselessColorCodes) { + Iterator itr = list.iterator(); + while (itr.hasNext()) { + BaseComponent base = itr.next(); + if (base instanceof TextComponent) { + TextComponent text = (TextComponent) base; + if (text.getText().matches("^(§[0-9,a-f,l-o,r])*$")) { + itr.remove(); + } else { + text.setText(ChatColorFilter.removeUselessColorCodes(text.getText())); + } + } + } } return list; } diff --git a/src/config.yml b/src/config.yml index 439f5984..e0de31e1 100644 --- a/src/config.yml +++ b/src/config.yml @@ -12,6 +12,8 @@ Messages: LimitReached: "&cPlease do now use excessive amount of placeholders in one message!" Settings: + #Turn this off if some colors are missing + FilterUselessColorCodes: true #A list of private message commands on your server #The plugin will attempt to parse placeholder inside these commands. #This list is in REGEX so you can do some more advanced matches. diff --git a/src/plugin.yml b/src/plugin.yml index fadfa52a..8c4f4316 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: InteractiveChat author: loohp -version: 2.1.0 +version: 2.1.1 main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive