From a808dc4c81962997ff3d1a546d17a3210326a583 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Fri, 1 May 2020 12:01:53 +0800 Subject: [PATCH] 2.1.5 Update --- .../Modules/CustomPlaceholderDisplay.java | 3 ++ .../Modules/EnderchestDisplay.java | 3 ++ .../Modules/InventoryDisplay.java | 3 ++ .../interactivechat/Modules/ItemDisplay.java | 3 ++ .../interactivechat/Utils/ChatColorUtils.java | 31 +++++++++++++++++++ src/plugin.yml | 2 +- 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java b/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java index adf19b1d..ecc686e1 100644 --- a/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java +++ b/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java @@ -12,6 +12,7 @@ import com.loohp.interactivechat.ConfigManager; import com.loohp.interactivechat.InteractiveChat; +import com.loohp.interactivechat.Utils.ChatColorUtils; import com.loohp.interactivechat.Utils.CustomStringUtils; import com.loohp.interactivechat.Utils.JsonUtils; @@ -113,7 +114,9 @@ public static BaseComponent processCustomPlaceholder(Player parseplayer, boolean boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase()); if ((trim.size() - 1) > i || endwith) { if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) { + String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText()); TextComponent message = new TextComponent(placeholder); + message = (TextComponent) ChatColorUtils.applyColor(message, color); ((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1)); newlist.add(message); } else { diff --git a/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java b/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java index 957ca6db..2b4adede 100644 --- a/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java +++ b/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java @@ -14,6 +14,7 @@ import com.loohp.interactivechat.ConfigManager; import com.loohp.interactivechat.InteractiveChat; +import com.loohp.interactivechat.Utils.ChatColorUtils; import com.loohp.interactivechat.Utils.CustomStringUtils; import com.loohp.interactivechat.Utils.JsonUtils; @@ -96,7 +97,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional i || endwith) { if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) { + String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText()); TextComponent message = new TextComponent(placeholder); + message = (TextComponent) ChatColorUtils.applyColor(message, color); ((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1)); newlist.add(message); } else { diff --git a/src/com/loohp/interactivechat/Modules/InventoryDisplay.java b/src/com/loohp/interactivechat/Modules/InventoryDisplay.java index 9c1b2c5c..dc28a1ce 100644 --- a/src/com/loohp/interactivechat/Modules/InventoryDisplay.java +++ b/src/com/loohp/interactivechat/Modules/InventoryDisplay.java @@ -14,6 +14,7 @@ import com.loohp.interactivechat.ConfigManager; import com.loohp.interactivechat.InteractiveChat; +import com.loohp.interactivechat.Utils.ChatColorUtils; import com.loohp.interactivechat.Utils.CustomStringUtils; import com.loohp.interactivechat.Utils.JsonUtils; @@ -96,7 +97,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional i || endwith) { if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) { + String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText()); TextComponent message = new TextComponent(placeholder); + message = (TextComponent) ChatColorUtils.applyColor(message, color); ((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1)); newlist.add(message); } else { diff --git a/src/com/loohp/interactivechat/Modules/ItemDisplay.java b/src/com/loohp/interactivechat/Modules/ItemDisplay.java index e112fb51..b9f9cf1f 100644 --- a/src/com/loohp/interactivechat/Modules/ItemDisplay.java +++ b/src/com/loohp/interactivechat/Modules/ItemDisplay.java @@ -17,6 +17,7 @@ import com.loohp.interactivechat.ConfigManager; import com.loohp.interactivechat.InteractiveChat; import com.loohp.interactivechat.Utils.ChatColorFilter; +import com.loohp.interactivechat.Utils.ChatColorUtils; import com.loohp.interactivechat.Utils.CustomStringUtils; import com.loohp.interactivechat.Utils.ItemNBTUtils; import com.loohp.interactivechat.Utils.JsonUtils; @@ -104,7 +105,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional i || endwith) { if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) { + String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText()); TextComponent message = new TextComponent(placeholder); + message = (TextComponent) ChatColorUtils.applyColor(message, color); ((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1)); newlist.add(message); } else { diff --git a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java index d1caf012..ba2aaba7 100644 --- a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java @@ -4,6 +4,7 @@ import java.util.List; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; public class ChatColorUtils { @@ -44,5 +45,35 @@ public static boolean isLegal(String color) { } return true; } + + public static BaseComponent applyColor(BaseComponent basecomponent, String color) { + if (color.length() >= 2 && color.charAt(1) != 'r') { + if (color.length() == 2) { + basecomponent.setColor(ChatColor.getByChar(color.charAt(1))); + } else if (color.length() == 4) { + basecomponent.setColor(ChatColor.getByChar(color.charAt(1))); + switch (ChatColor.getByChar(color.charAt(3))) { + case BOLD: + basecomponent.setBold(true); + break; + case ITALIC: + basecomponent.setItalic(true); + break; + case MAGIC: + basecomponent.setObfuscated(true); + break; + case STRIKETHROUGH: + basecomponent.setStrikethrough(true); + break; + case UNDERLINE: + basecomponent.setUnderlined(true); + break; + default: + break; + } + } + } + return basecomponent; + } } diff --git a/src/plugin.yml b/src/plugin.yml index 799ab11e..2df2d8ac 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: InteractiveChat author: loohp -version: 2.1.4 +version: 2.1.5 main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive