diff --git a/src/com/loohp/interactivechat/Listeners/ChatPackets.java b/src/com/loohp/interactivechat/Listeners/ChatPackets.java index a8c5e316..54b27833 100644 --- a/src/com/loohp/interactivechat/Listeners/ChatPackets.java +++ b/src/com/loohp/interactivechat/Listeners/ChatPackets.java @@ -111,7 +111,7 @@ public void onPacketSending(PacketEvent event) { basecomponent = CustomPlaceholderDisplay.process(basecomponent, sender, event.getPlayer(), rawMessageKey, unix); - basecomponentarray[0] = InteractiveChat.FilterUselessColorCodes ? ChatComponentUtils.cleanUpLegacyText(basecomponent) : basecomponent; + basecomponentarray[0] = InteractiveChat.FilterUselessColorCodes ? ChatComponentUtils.cleanUpLegacyText(basecomponent, event.getPlayer()) : basecomponent; if (field == 0) { packet.getChatComponents().write(0, WrappedChatComponent.fromJson(ComponentSerializer.toString(basecomponentarray))); } else { diff --git a/src/com/loohp/interactivechat/Modules/PlayernameDisplay.java b/src/com/loohp/interactivechat/Modules/PlayernameDisplay.java index 3020a69e..a96c99c1 100644 --- a/src/com/loohp/interactivechat/Modules/PlayernameDisplay.java +++ b/src/com/loohp/interactivechat/Modules/PlayernameDisplay.java @@ -54,7 +54,7 @@ public static BaseComponent processPlayer(String placeholder, Player player, Str List newlist = new ArrayList(); for (BaseComponent base : basecomponentlist) { - if (matched.stream().anyMatch(each -> ChatComponentUtils.areSimilar(each, base))) { + if (matched.stream().anyMatch(each -> ChatComponentUtils.areSimilar(each, base, true))) { newlist.add(base); } else if (!(base instanceof TextComponent)) { newlist.add(base); diff --git a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java index dcc535f7..6ff14087 100644 --- a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java @@ -4,13 +4,14 @@ import java.util.List; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; public class ChatComponentUtils { - public static boolean areSimilar(BaseComponent base1, BaseComponent base2) { + public static boolean areSimilar(BaseComponent base1, BaseComponent base2, boolean compareText) { if (!areEventsSimilar(base1, base2)) { return false; } @@ -32,6 +33,9 @@ public static boolean areSimilar(BaseComponent base1, BaseComponent base2) { if (base1.isUnderlined() != base2.isUnderlined()) { return false; } + if (compareText && !base1.toLegacyText().equals(base2.toLegacyText())) { + return false; + } return true; } @@ -56,7 +60,7 @@ public static boolean areEventsSimilar(BaseComponent base1, BaseComponent base2) return clickSim && hoverSim; } - public static BaseComponent cleanUpLegacyText(BaseComponent basecomponent) { + public static BaseComponent cleanUpLegacyText(BaseComponent basecomponent, Player player) { List newlist = new LinkedList(); for (BaseComponent base : CustomStringUtils.loadExtras(basecomponent)) { if (!(base instanceof TextComponent)) { @@ -73,15 +77,22 @@ public static BaseComponent cleanUpLegacyText(BaseComponent basecomponent) { TextComponent newTextComponent = new TextComponent(ChatColor.stripColor(before)); newTextComponent = (TextComponent) CustomStringUtils.copyFormatting(newTextComponent, textcomponent); newTextComponent = (TextComponent) ChatColorUtils.applyColor(newTextComponent, color); - newlist.add(newTextComponent); + if (!newlist.isEmpty() && areSimilar(newTextComponent, newlist.get(newlist.size() - 1), false)) { + TextComponent lastTextComponent = (TextComponent) newlist.get(newlist.size() - 1); + lastTextComponent.setText(lastTextComponent.getText() + newTextComponent.getText()); + } else { + newlist.add(newTextComponent); + } } while (text.contains("§")); } } + TextComponent product = new TextComponent(""); for (int i = 0; i < newlist.size(); i++) { BaseComponent each = newlist.get(i); product.addExtra(each); } + return product; } diff --git a/src/plugin.yml b/src/plugin.yml index a05d9484..c99a15b7 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: InteractiveChat author: loohp -version: 2.1.10 +version: 2.1.11 main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive