diff --git a/src/com/loohp/interactivechat/API/InteractiveChatAPI.java b/src/com/loohp/interactivechat/API/InteractiveChatAPI.java index d472e89f..657e42b3 100644 --- a/src/com/loohp/interactivechat/API/InteractiveChatAPI.java +++ b/src/com/loohp/interactivechat/API/InteractiveChatAPI.java @@ -1,7 +1,8 @@ package com.loohp.interactivechat.API; -import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -29,7 +30,7 @@ public static void setPlayerMentionCooldown(Player player, long time) { InteractiveChat.mentionCooldown.put(player, time); } - public static HashMap getMentionCooldownMap() { + public static Map getMentionCooldownMap() { return InteractiveChat.mentionCooldown; } @@ -44,7 +45,7 @@ public static long getPlayerPlaceholderCooldown(Player player, String placeholde public static void setPlayerPlaceholderCooldown(Player player, String placeholder, long time) { if (!InteractiveChat.placeholderCooldowns.containsKey(player)) { - InteractiveChat.placeholderCooldowns.put(player, new HashMap()); + InteractiveChat.placeholderCooldowns.put(player, new ConcurrentHashMap()); } InteractiveChat.placeholderCooldowns.get(player).put(placeholder, time); } @@ -81,11 +82,11 @@ public static boolean isPlaceholderOnCooldown(Player player, String placeholder, return false; } - public static HashMap getInventoryShareList() { + public static Map getInventoryShareList() { return InteractiveChat.inventoryDisplay; } - public static HashMap getEnderShareList() { + public static Map getEnderShareList() { return InteractiveChat.enderDisplay; } } diff --git a/src/com/loohp/interactivechat/ConfigManager.java b/src/com/loohp/interactivechat/ConfigManager.java index 1f6efa66..3125671a 100644 --- a/src/com/loohp/interactivechat/ConfigManager.java +++ b/src/com/loohp/interactivechat/ConfigManager.java @@ -143,5 +143,6 @@ public static void loadConfig() { InteractiveChat.mentionDuration = getConfig().getLong("Chat.MentionedTitleDuration"); InteractiveChat.UpdaterEnabled = InteractiveChat.plugin.getConfig().getBoolean("Options.Updater"); + InteractiveChat.cancelledMessage = InteractiveChat.plugin.getConfig().getBoolean("Options.ShowCancelledNotice"); } } \ No newline at end of file diff --git a/src/com/loohp/interactivechat/InteractiveChat.java b/src/com/loohp/interactivechat/InteractiveChat.java index ea96a0ef..2d03a96f 100644 --- a/src/com/loohp/interactivechat/InteractiveChat.java +++ b/src/com/loohp/interactivechat/InteractiveChat.java @@ -5,7 +5,6 @@ import java.io.InputStream; import java.nio.file.Files; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.UUID; @@ -95,39 +94,40 @@ public class InteractiveChat extends JavaPlugin { public static String InvExpired = "&cThis inventory view has expired!"; public static String ReloadPlugin = "&aInteractive Chat has been reloaded!"; - public static HashMap messages = new HashMap(); - public static HashMap keyTime = new HashMap(); - public static HashMap keyPlayer = new HashMap(); + public static ConcurrentHashMap messages = new ConcurrentHashMap(); + public static ConcurrentHashMap keyTime = new ConcurrentHashMap(); + public static ConcurrentHashMap keyPlayer = new ConcurrentHashMap(); - public static HashMap> cooldownbypass = new HashMap>(); + public static ConcurrentHashMap> cooldownbypass = new ConcurrentHashMap>(); - public static HashMap itemDisplay = new HashMap(); - public static HashMap inventoryDisplay = new HashMap(); - public static HashMap enderDisplay = new HashMap(); + public static ConcurrentHashMap itemDisplay = new ConcurrentHashMap(); + public static ConcurrentHashMap inventoryDisplay = new ConcurrentHashMap(); + public static ConcurrentHashMap enderDisplay = new ConcurrentHashMap(); - public static HashMap> placeholderCooldowns = new HashMap>(); - public static HashMap universalCooldowns = new HashMap(); + public static ConcurrentHashMap> placeholderCooldowns = new ConcurrentHashMap>(); + public static ConcurrentHashMap universalCooldowns = new ConcurrentHashMap(); public static List placeholderList = new ArrayList(); public static int maxPlacholders = -1; public static String limitReachMessage = "&cPlease do now use excessive amount of placeholders in one message!"; - public static HashMap mentionCooldown = new HashMap(); - public static HashMap mentionPair = new HashMap(); + public static ConcurrentHashMap mentionCooldown = new ConcurrentHashMap(); + public static ConcurrentHashMap mentionPair = new ConcurrentHashMap(); public static String mentionHightlight = "&e{MentionedPlayer}"; public static String mentionHover = "&e{MentionedPlayer}"; public static long mentionDuration = 2; public static List commandList = new ArrayList(); - public static HashMap commandPlaceholderMatch = new HashMap(); + public static ConcurrentHashMap commandPlaceholderMatch = new ConcurrentHashMap(); public static ConcurrentHashMap essenNick = new ConcurrentHashMap(); public static boolean FilterUselessColorCodes = true; - public static HashMap aliasesMapping = new HashMap(); + public static ConcurrentHashMap aliasesMapping = new ConcurrentHashMap(); public static boolean UpdaterEnabled = true; + public static boolean cancelledMessage = true; @Override public void onEnable() { diff --git a/src/com/loohp/interactivechat/Listeners/ChatPackets.java b/src/com/loohp/interactivechat/Listeners/ChatPackets.java index 05decfe1..03c5fede 100644 --- a/src/com/loohp/interactivechat/Listeners/ChatPackets.java +++ b/src/com/loohp/interactivechat/Listeners/ChatPackets.java @@ -26,6 +26,7 @@ import com.loohp.interactivechat.Modules.ProcessCommands; import com.loohp.interactivechat.Modules.SenderFinder; import com.loohp.interactivechat.ObjectHolders.ProcessCommandsReturn; +import com.loohp.interactivechat.Utils.ChatColorFilter; import com.loohp.interactivechat.Utils.ChatComponentUtils; import com.loohp.interactivechat.Utils.JsonUtils; import com.loohp.interactivechat.Utils.MCVersion; @@ -40,13 +41,15 @@ public static void chatMessageListener() { InteractiveChat.protocolManager.addPacketListener(new PacketAdapter(InteractiveChat.plugin, ListenerPriority.MONITOR, PacketType.Play.Server.CHAT) { @Override public void onPacketSending(PacketEvent event) { + int debug = 0; + try { if (!event.getPacketType().equals(PacketType.Play.Server.CHAT)) { return; } - + debug++; PacketContainer packet = event.getPacket(); Player reciever = event.getPlayer(); - + debug++; if (!InteractiveChat.version.isLegacy() || InteractiveChat.version.equals(MCVersion.V1_12)) { ChatType type = packet.getChatTypes().read(0); if (type.equals(ChatType.GAME_INFO)) { @@ -58,15 +61,17 @@ public void onPacketSending(PacketEvent event) { return; } } - + debug++; WrappedChatComponent wcc = packet.getChatComponents().read(0); Object field1 = packet.getModifier().read(1); if (wcc == null && field1 == null) { return; } + debug++; BaseComponent[] basecomponentarray = (wcc != null) ? ComponentSerializer.parse(wcc.getJson()) : (BaseComponent[]) field1; int field = (wcc != null) ? 0 : 1; - BaseComponent basecomponent = basecomponentarray[0]; + BaseComponent basecomponent = ComponentSerializer.parse(ChatColorFilter.filterIllegalColorCodes(ComponentSerializer.toString(basecomponentarray)))[0]; + debug++; try { if (basecomponent.toLegacyText().equals("")) { return; @@ -74,30 +79,33 @@ public void onPacketSending(PacketEvent event) { } catch (Exception e) { return; } - + debug++; if ((InteractiveChat.version.isOld()) && JsonUtils.containsKey(ComponentSerializer.toString(basecomponent), "translate")) { return; } - + debug++; String rawMessageKey = basecomponent.toPlainText(); if (!InteractiveChat.keyTime.containsKey(rawMessageKey)) { InteractiveChat.keyTime.put(rawMessageKey, System.currentTimeMillis()); } + debug++; long unix = InteractiveChat.keyTime.get(rawMessageKey); if (!InteractiveChat.cooldownbypass.containsKey(unix)) { InteractiveChat.cooldownbypass.put(unix, new HashSet()); } + debug++; ProcessCommandsReturn commandsender = ProcessCommands.process(basecomponent); Optional sender = commandsender.getSender() != null ? Optional.of(commandsender.getSender()) : SenderFinder.getSender(basecomponent, rawMessageKey); basecomponent = commandsender.getBaseComponent(); if (sender.isPresent()) { InteractiveChat.keyPlayer.put(rawMessageKey, sender.get()); } + debug++; Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> { InteractiveChat.keyTime.remove(rawMessageKey); InteractiveChat.keyPlayer.remove(rawMessageKey); }, 5); - + debug++; UUID preEventSenderUUID = sender.isPresent() ? sender.get().getUniqueId() : null; PrePacketComponentProcessEvent preEvent = new PrePacketComponentProcessEvent(event.isAsync(), reciever, basecomponent, field, preEventSenderUUID); Bukkit.getPluginManager().callEvent(preEvent); @@ -107,53 +115,59 @@ public void onPacketSending(PacketEvent event) { sender = Optional.of(newsender); } } - + debug++; if (InteractiveChat.usePlayerName) { basecomponent = PlayernameDisplay.process(basecomponent, rawMessageKey, sender, unix); } - + debug++; if (InteractiveChat.AllowMention && sender.isPresent()) { basecomponent = MentionDisplay.process(basecomponent, reciever, sender.get(), rawMessageKey, unix, event.isAsync()); } - + debug++; if (InteractiveChat.useItem) { basecomponent = ItemDisplay.process(basecomponent, sender, reciever, rawMessageKey, unix); } - + debug++; if (InteractiveChat.useInventory) { basecomponent = InventoryDisplay.process(basecomponent, sender, rawMessageKey, unix); } - + debug++; if (InteractiveChat.useEnder) { basecomponent = EnderchestDisplay.process(basecomponent, sender, rawMessageKey, unix); } - + debug++; basecomponent = CustomPlaceholderDisplay.process(basecomponent, sender, reciever, rawMessageKey, unix); - + debug++; basecomponentarray[0] = InteractiveChat.FilterUselessColorCodes ? ChatComponentUtils.cleanUpLegacyText(basecomponent, reciever) : ChatComponentUtils.respectClientColorSettingsWithoutCleanUp(basecomponent, reciever); String json = ComponentSerializer.toString(basecomponentarray); boolean longerThanMaxLength = false; if ((InteractiveChat.version.isLegacy() || InteractiveChat.protocolManager.getProtocolVersion(reciever) < 393) && json.length() > 32767) { longerThanMaxLength = true; } - + debug++; if (field == 0) { packet.getChatComponents().write(0, WrappedChatComponent.fromJson(json)); } else { packet.getModifier().write(1, basecomponentarray); } - + debug++; UUID postEventSenderUUID = sender.isPresent() ? sender.get().getUniqueId() : null; PostPacketComponentProcessEvent postEvent = new PostPacketComponentProcessEvent(event.isAsync(), reciever, packet, postEventSenderUUID, longerThanMaxLength); Bukkit.getPluginManager().callEvent(postEvent); + debug++; if (postEvent.isCancelled()) { event.setReadOnly(false); event.setCancelled(true); event.setReadOnly(true); - if (longerThanMaxLength) { + if (longerThanMaxLength && InteractiveChat.cancelledMessage) { Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[InteractiveChat] " + ChatColor.RED + "Cancelled a chat packet bounded to " + reciever.getName() + " that is " + json.length() + " characters long (Max 32767) [THIS IS NOT A BUG]"); } - } + } + debug++; + } catch (Exception e) { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IC DEBUG " + event.getPlayer().getName() + " " + debug); + e.printStackTrace(); + } } }); } diff --git a/src/com/loohp/interactivechat/Listeners/Events.java b/src/com/loohp/interactivechat/Listeners/Events.java index 1620da4d..6c3d155e 100644 --- a/src/com/loohp/interactivechat/Listeners/Events.java +++ b/src/com/loohp/interactivechat/Listeners/Events.java @@ -150,29 +150,13 @@ private void checkMention(AsyncPlayerChatEvent event) { for (String name : playernames) { int index = message.toLowerCase().indexOf(name.toLowerCase()); if (index >= 0) { - char escape = (index - 1) < 0 ? ' ' : message.charAt(index - 1); + char before = (index - 1) < 0 ? ' ' : message.charAt(index - 1); char after = (index + name.length()) >= message.length() ? ' ' : message.charAt(index + name.length()); - if (String.valueOf(escape).matches("[ \\\\]") && String.valueOf(after).matches("[ \\\\]")) { - char escapeescape = (index - 2) < 0 ? ' ' : message.charAt(index - 2); - if ((escape != '\\') || ((escape == '\\' && escapeescape == '\\'))) { - if (escapeescape == '\\') { - StringBuilder sb = new StringBuilder(message); - sb.deleteCharAt(index - 2); - event.setMessage(sb.toString()); - message = event.getMessage(); - } - if (!player.equals(sender)) { - InteractiveChat.mentionPair.put(player.getUniqueId(), new MentionPair(sender.getUniqueId(), player.getUniqueId(), InteractiveChat.mentionPair)); - } - break; - } else { - if (escape == '\\') { - StringBuilder sb = new StringBuilder(message); - sb.deleteCharAt(index - 1); - event.setMessage(sb.toString()); - message = event.getMessage(); - } - } + if (String.valueOf(before).matches("[^a-zA-Z0-9]") && String.valueOf(after).matches("[^a-zA-Z0-9]")) { + if (!player.equals(sender)) { + InteractiveChat.mentionPair.put(player.getUniqueId(), new MentionPair(sender.getUniqueId(), player.getUniqueId(), InteractiveChat.mentionPair)); + } + break; } } } diff --git a/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java b/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java index 8bc4fd16..1e0de6d6 100644 --- a/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java +++ b/src/com/loohp/interactivechat/Modules/CustomPlaceholderDisplay.java @@ -2,11 +2,11 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -28,8 +28,8 @@ public class CustomPlaceholderDisplay { - private static HashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; - private static HashMap universalCooldowns = InteractiveChat.universalCooldowns; + private static ConcurrentHashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; + private static ConcurrentHashMap universalCooldowns = InteractiveChat.universalCooldowns; private static Random random = new Random(); public static BaseComponent process(BaseComponent basecomponent, Optional optplayer, Player reciever, String messageKey, long unix) { @@ -70,9 +70,9 @@ public static BaseComponent processCustomPlaceholder(Player parseplayer, boolean } if (!placeholderCooldowns.containsKey(player)) { - placeholderCooldowns.put(player, new HashMap()); + placeholderCooldowns.put(player, new ConcurrentHashMap()); } - HashMap spmap = placeholderCooldowns.get(player); + ConcurrentHashMap spmap = placeholderCooldowns.get(player); if (spmap.containsKey(placeholder)) { if (spmap.get(placeholder) > unix) { if (!player.hasPermission("interactivechat.cooldown.bypass")) { diff --git a/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java b/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java index 915c42b8..0be68cad 100644 --- a/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java +++ b/src/com/loohp/interactivechat/Modules/EnderchestDisplay.java @@ -6,6 +6,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -29,8 +30,8 @@ public class EnderchestDisplay { - private static HashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; - private static HashMap universalCooldowns = InteractiveChat.universalCooldowns; + private static ConcurrentHashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; + private static ConcurrentHashMap universalCooldowns = InteractiveChat.universalCooldowns; public static BaseComponent process(BaseComponent basecomponent, Optional optplayer, String messageKey, long unix) { boolean contain = (InteractiveChat.enderCaseSensitive) ? (basecomponent.toPlainText().contains(InteractiveChat.enderPlaceholder)) : (basecomponent.toPlainText().toLowerCase().contains(InteractiveChat.enderPlaceholder.toLowerCase())); @@ -45,9 +46,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional()); + placeholderCooldowns.put(player, new ConcurrentHashMap()); } - HashMap spmap = placeholderCooldowns.get(player); + ConcurrentHashMap spmap = placeholderCooldowns.get(player); if (spmap.containsKey(InteractiveChat.enderPlaceholder)) { if (spmap.get(InteractiveChat.enderPlaceholder) > unix) { if (!player.hasPermission("interactivechat.cooldown.bypass")) { diff --git a/src/com/loohp/interactivechat/Modules/InventoryDisplay.java b/src/com/loohp/interactivechat/Modules/InventoryDisplay.java index 02752683..f6a7798d 100644 --- a/src/com/loohp/interactivechat/Modules/InventoryDisplay.java +++ b/src/com/loohp/interactivechat/Modules/InventoryDisplay.java @@ -6,6 +6,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -29,8 +30,8 @@ public class InventoryDisplay { - private static HashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; - private static HashMap universalCooldowns = InteractiveChat.universalCooldowns; + private static ConcurrentHashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; + private static ConcurrentHashMap universalCooldowns = InteractiveChat.universalCooldowns; public static BaseComponent process(BaseComponent basecomponent, Optional optplayer, String messageKey, long unix) { boolean contain = (InteractiveChat.invCaseSensitive) ? (basecomponent.toPlainText().contains(InteractiveChat.invPlaceholder)) : (basecomponent.toPlainText().toLowerCase().contains(InteractiveChat.invPlaceholder.toLowerCase())); @@ -45,9 +46,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional()); + placeholderCooldowns.put(player, new ConcurrentHashMap()); } - HashMap spmap = placeholderCooldowns.get(player); + ConcurrentHashMap spmap = placeholderCooldowns.get(player); if (spmap.containsKey(InteractiveChat.invPlaceholder)) { if (spmap.get(InteractiveChat.invPlaceholder) > unix) { if (!player.hasPermission("interactivechat.cooldown.bypass")) { diff --git a/src/com/loohp/interactivechat/Modules/ItemDisplay.java b/src/com/loohp/interactivechat/Modules/ItemDisplay.java index 86404ace..2bef9a1a 100644 --- a/src/com/loohp/interactivechat/Modules/ItemDisplay.java +++ b/src/com/loohp/interactivechat/Modules/ItemDisplay.java @@ -6,6 +6,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -39,8 +40,8 @@ public class ItemDisplay { - private static HashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; - private static HashMap universalCooldowns = InteractiveChat.universalCooldowns; + private static ConcurrentHashMap> placeholderCooldowns = InteractiveChat.placeholderCooldowns; + private static ConcurrentHashMap universalCooldowns = InteractiveChat.universalCooldowns; @SuppressWarnings("deprecation") public static BaseComponent process(BaseComponent basecomponent, Optional optplayer, Player reciever, String messageKey, long unix) { @@ -56,9 +57,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional()); + placeholderCooldowns.put(player, new ConcurrentHashMap()); } - HashMap spmap = placeholderCooldowns.get(player); + ConcurrentHashMap spmap = placeholderCooldowns.get(player); if (spmap.containsKey(InteractiveChat.itemPlaceholder)) { if (spmap.get(InteractiveChat.itemPlaceholder) > unix) { if (!player.hasPermission("interactivechat.cooldown.bypass")) { @@ -366,7 +367,7 @@ public static BaseComponent process(BaseComponent basecomponent, Optional messages = InteractiveChat.messages; + private static ConcurrentHashMap messages = InteractiveChat.messages; public static Optional getSender(BaseComponent basecomponent, String messageKey) { Player keyPlayer = InteractiveChat.keyPlayer.get(messageKey); diff --git a/src/com/loohp/interactivechat/ObjectHolders/CommandPlaceholderInfo.java b/src/com/loohp/interactivechat/ObjectHolders/CommandPlaceholderInfo.java index 8bad41b8..76d94a79 100644 --- a/src/com/loohp/interactivechat/ObjectHolders/CommandPlaceholderInfo.java +++ b/src/com/loohp/interactivechat/ObjectHolders/CommandPlaceholderInfo.java @@ -1,7 +1,7 @@ package com.loohp.interactivechat.ObjectHolders; -import java.util.HashMap; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -13,9 +13,9 @@ public class CommandPlaceholderInfo { String placeholder; String uuidmatch; UUID sender; - HashMap map; + ConcurrentHashMap map; - public CommandPlaceholderInfo(Player sender, String placeholder, String uuidmatch, HashMap mapToRemoveFrom) { + public CommandPlaceholderInfo(Player sender, String placeholder, String uuidmatch, ConcurrentHashMap mapToRemoveFrom) { this.placeholder = placeholder; this.uuidmatch = uuidmatch; this.sender = sender.getUniqueId(); diff --git a/src/com/loohp/interactivechat/Utils/ChatColorFilter.java b/src/com/loohp/interactivechat/Utils/ChatColorFilter.java index a25e2363..cda8aea9 100644 --- a/src/com/loohp/interactivechat/Utils/ChatColorFilter.java +++ b/src/com/loohp/interactivechat/Utils/ChatColorFilter.java @@ -11,17 +11,17 @@ public class ChatColorFilter { public static String removeUselessColorCodes(String string) { - return string.replaceAll("(§[0-9a-fl-or])*(?=§[0-9a-fr])", ""); + return string.replaceAll("(§[0-9a-fk-or])*(?=§[0-9a-fr])", ""); } public static String filterIllegalColorCodes(String string) { - return string.replaceAll("§[g-j,p,q,s-z,A-Z,\\-!$%^&*()_+|~=`{}\\[\\]:\";'<>?,.\\/\\\\]", "§r"); + return string.replaceAll("§[^0-9a-fk-or]", ""); } public static BaseComponent filterExtraColorCodes(BaseComponent baseComponent) { if (baseComponent instanceof TextComponent) { TextComponent text = (TextComponent) baseComponent; - if (text.getText().matches("^(§[0-9,a-f,l-o,r])*$")) { + if (text.getText().matches("^(§[0-9a-fk-or])*$")) { text.setText(""); } } @@ -36,7 +36,7 @@ public static List filterUselessColorCodes(List ba BaseComponent base = itr.next(); if (base instanceof TextComponent) { TextComponent text = (TextComponent) base; - if (text.getText().matches("^(§[0-9,a-f,l-o,r])*$")) { + if (text.getText().matches("^(§[0-9a-fk-or])*$")) { itr.remove(); } else { text.setText(ChatColorFilter.removeUselessColorCodes(text.getText())); diff --git a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java index e6c22e4c..3aeab364 100644 --- a/src/com/loohp/interactivechat/Utils/ChatColorUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatColorUtils.java @@ -75,10 +75,10 @@ public static boolean isLegal(String color) { if (color.charAt(0) != '§') { return false; } - if (color.matches("§[g-j,p,q,s-z,A-Z,\\-!$%^&*()_+|~=`{}\\[\\]:\\\";'<>?,.\\/\\\\]")) { - return false; + if (color.matches("§[0-9a-fk-or]")) { + return true; } - return true; + return false; } public static BaseComponent applyColor(BaseComponent basecomponent, String color) { diff --git a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java index 6856c808..d551d965 100644 --- a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java @@ -3,6 +3,7 @@ import java.util.LinkedList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import com.loohp.interactivechat.Listeners.ClientSettingPackets; @@ -49,6 +50,36 @@ public static boolean areSimilar(BaseComponent base1, BaseComponent base2, boole return true; } + public static boolean areSimilarNoEvents(BaseComponent base1, BaseComponent base2, boolean compareText) { + if ((base1.getColor() == null && base2.getColor() != null) || (base1.getColor() != null && base2.getColor() == null)) { + return false; + } + if (base1.getColor() != null && base2.getColor() != null) { + if (!base1.getColor().equals(base2.getColor())) { + return false; + } + } + if (base1.isBold() != base2.isBold()) { + return false; + } + if (base1.isItalic() != base2.isItalic()) { + return false; + } + if (base1.isObfuscated() != base2.isObfuscated()) { + return false; + } + if (base1.isStrikethrough() != base2.isStrikethrough()) { + return false; + } + if (base1.isUnderlined() != base2.isUnderlined()) { + return false; + } + if (compareText && !base1.toLegacyText().equals(base2.toLegacyText())) { + return false; + } + return true; + } + public static boolean areEventsSimilar(BaseComponent base1, BaseComponent base2) { boolean clickSim = false; boolean hoverSim = false; @@ -58,10 +89,14 @@ public static boolean areEventsSimilar(BaseComponent base1, BaseComponent base2) if (base1.getClickEvent() != null && base2.getClickEvent() != null) { ClickEvent click1 = base1.getClickEvent(); ClickEvent click2 = base2.getClickEvent(); - if (click1.getAction().equals(click2.getAction())) { + if (click1.getAction() == null && click2.getAction() == null) { + clickSim = true; + } else if ((click1 != null && click2 != null) && click1.getAction().equals(click2.getAction())) { String value1 = click1.getValue(); String value2 = click2.getValue(); - if (value1.equals(value2)) { + if (value1 == null && value2 == null) { + clickSim = true; + } else if ((value1 != null && value2 != null) && value1.equals(value2)) { clickSim = true; } } @@ -76,18 +111,19 @@ public static boolean areEventsSimilar(BaseComponent base1, BaseComponent base2) if (hover1.getAction().equals(hover2.getAction())) { BaseComponent[] basecomponentarray1 = hover1.getValue(); BaseComponent[] basecomponentarray2 = hover2.getValue(); - hoverSim = true; if (basecomponentarray1.length == basecomponentarray2.length) { + hoverSim = true; for (int i = 0; i < basecomponentarray1.length && i < basecomponentarray2.length ; i++) { BaseComponent bc1 = basecomponentarray1[i]; BaseComponent bc2 = basecomponentarray2[i]; - if (!areSimilar(bc1, bc2, true)) { + if (!(bc1 == null && bc2 == null) && (bc1 == null || bc2 == null)) { + hoverSim = false; + break; + } else if (areSimilarNoEvents(bc1, bc2, true)) { hoverSim = false; break; } } - } else { - hoverSim = false; } } } @@ -119,7 +155,9 @@ public static BaseComponent cleanUpLegacyText(BaseComponent basecomponent, Playe } else { TextComponent textcomponent = (TextComponent) base; String text = textcomponent.getText(); + int loop = 0; do { + loop++; String color = ChatColorUtils.getFirstColors(text); int pos = CustomStringUtils.ordinalIndexOf(text, "§", CustomStringUtils.occurrencesOfSubstring(color, "§") + 1); pos = pos >= 0 ? pos : text.length(); @@ -134,7 +172,11 @@ public static BaseComponent cleanUpLegacyText(BaseComponent basecomponent, Playe } else { newlist.add(newTextComponent); } - } while (text.contains("§")); + if (loop > 5000) { + Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[InteractiveChat] Debug - cleanUpLegacyText loop 5000 - " + text.toString()); + break; + } + } while (text.contains("§") && !text.equals("§")); } } diff --git a/src/config.yml b/src/config.yml index 91df6145..59c6353c 100644 --- a/src/config.yml +++ b/src/config.yml @@ -1,5 +1,6 @@ Options: Updater: true + ShowCancelledNotice: true Messages: NoPermission: "&cYou do not have permission to use that command!" diff --git a/src/plugin.yml b/src/plugin.yml index be345b5d..d6f6043a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: InteractiveChat author: loohp -version: 2.2.4 +version: 2.2.5 main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive