From d4f0c518e4a77b3c4710aeca87076cd0ea707029 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Sun, 5 Jul 2020 19:00:20 +0800 Subject: [PATCH] 2.6.1 Update --- .../interactivechat/Listeners/Events.java | 22 ++++++++++++++++ .../interactivechat/Utils/ChatColorUtils.java | 16 ++++++++++++ .../Utils/ChatComponentUtils.java | 25 ++++++++++++++++++- src/plugin.yml | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/com/loohp/interactivechat/Listeners/Events.java b/src/com/loohp/interactivechat/Listeners/Events.java index 1b5d3d1b..328cebd6 100644 --- a/src/com/loohp/interactivechat/Listeners/Events.java +++ b/src/com/loohp/interactivechat/Listeners/Events.java @@ -41,6 +41,9 @@ public void onLeave(PlayerQuitEvent event) { @EventHandler(priority=EventPriority.HIGH) public void onCommand(PlayerCommandPreprocessEvent event) { + + translateAltColorCode(event); + String command = event.getMessage(); for (String parsecommand : InteractiveChat.commandList) { if (command.matches(parsecommand)) { @@ -193,6 +196,25 @@ private void translateAltColorCode(AsyncPlayerChatEvent event) { event.setMessage(message); } + private void translateAltColorCode(PlayerCommandPreprocessEvent event) { + if (event.isCancelled()) { + return; + } + + if (!InteractiveChat.chatAltColorCode.isPresent()) { + return; + } + + Player player = event.getPlayer(); + + if (!player.hasPermission("interactivechat.chatcolor.translate")) { + return; + } + + String message = ChatColorUtils.translateAlternateColorCodes(InteractiveChat.chatAltColorCode.get(), event.getMessage()); + event.setMessage(message); + } + @EventHandler(priority=EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent event) { if (event.getClickedInventory() == null) { diff --git a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java index 965520fe..217835e6 100644 --- a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java @@ -16,6 +16,7 @@ public class ChatColorUtils { private static Set colors = new HashSet(); private static Pattern colorFormating = Pattern.compile("(?=(? 2 && sb.charAt(absPos - 2) == '\\' && sb.charAt(absPos - 3) == '\\') { + sb.deleteCharAt(absPos - 2); + } + + text = sb.toString(); + } else { + break; + } + } + + while (true) { + Matcher matcher = colorEscape.matcher(text); + if (matcher.find()) { + StringBuilder sb = new StringBuilder(text); + sb.deleteCharAt(matcher.start()); text = sb.toString(); } else { break; diff --git a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java index a53cf985..aee987d8 100644 --- a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java @@ -35,6 +35,7 @@ public class ChatComponentUtils { private static MethodHandle hoverEventGetValueMethod; private static Pattern fontFormating = Pattern.compile("(?=(? 2 && sb.charAt(absPos - 2) == '\\' && sb.charAt(absPos - 3) == '\\') { + sb.deleteCharAt(absPos - 2); + absPos--; } absPos--; @@ -464,7 +470,9 @@ public static BaseComponent translatePluginFontFormatting(BaseComponent basecomp textlist.add(before); break; } - } + + } + newlist.addAll(textlist); } else { if (currentFont.isPresent()) { @@ -477,6 +485,21 @@ public static BaseComponent translatePluginFontFormatting(BaseComponent basecomp TextComponent product = new TextComponent(""); for (int i = 0; i < newlist.size(); i++) { BaseComponent each = newlist.get(i); + if (each instanceof TextComponent) { + TextComponent text = (TextComponent) each; + String str = text.getText(); + while (true) { + Matcher matcher = fontEscape.matcher(str); + if (matcher.find()) { + StringBuilder sb = new StringBuilder(str); + sb.deleteCharAt(matcher.start()); + str = sb.toString(); + } else { + text.setText(str); + break; + } + } + } product.addExtra(each); } diff --git a/src/plugin.yml b/src/plugin.yml index a66da931..27408064 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: InteractiveChat author: loohp -version: 2.6.0 +version: 2.6.1 main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive