Skip to content

Commit

Permalink
2.1.11 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed May 7, 2020
1 parent 422554c commit abb6367
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Listeners/ChatPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static BaseComponent processPlayer(String placeholder, Player player, Str
List<BaseComponent> newlist = new ArrayList<BaseComponent>();

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);
Expand Down
17 changes: 14 additions & 3 deletions src/com/loohp/interactivechat/Utils/ChatComponentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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<BaseComponent> newlist = new LinkedList<BaseComponent>();
for (BaseComponent base : CustomStringUtils.loadExtras(basecomponent)) {
if (!(base instanceof TextComponent)) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit abb6367

Please sign in to comment.