From b6878bfa74e2d9cb4c707cd5ff1c2b77f44cf123 Mon Sep 17 00:00:00 2001 From: daniel-skopek Date: Thu, 23 Jul 2026 01:57:11 +0200 Subject: [PATCH 1/4] fix: strip Shulker Box container data from [item] hover event Prevents oversized chat packets when displaying containers filled with enchanted items by trimming minecraft:container from the data components used in the hover event. --- .../java/com/loohp/interactivechat/modules/ItemDisplay.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java index 3f5e4848..85b563a9 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java @@ -185,7 +185,7 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item String itemJson = ItemNBTUtils.getNMSItemStackJson(item); ItemStack trimmedItem = null; - if (InteractiveChat.sendOriginalIfTooLong && itemJson.length() > InteractiveChat.itemTagMaxLength) { + if (useInventoryView(item) || (InteractiveChat.sendOriginalIfTooLong && itemJson.length() > InteractiveChat.itemTagMaxLength)) { trimmedItem = new ItemStack(item.getType()); trimmedItem.addUnsafeEnchantments(item.getEnchantments()); if (itemMeta != null && itemMeta.hasDisplayName()) { @@ -222,6 +222,8 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item showHover = false; } Map dataComponents = ItemNBTUtils.getNMSItemStackDataComponents(trimmedItem == null ? item : trimmedItem); + dataComponents.remove(Key.key("minecraft", "container")); + dataComponents.remove(Key.key("minecraft", "bundle_contents")); showItem = dataComponents.isEmpty() ? ShowItem.showItem(key, itemAmount) : ShowItem.showItem(key, itemAmount, dataComponents); } else { String tag = ItemNBTUtils.getNMSItemStackTag(trimmedItem == null ? item : trimmedItem); From 13ca2cfd8c076d23ab21616b047a8cbaef4a6a97 Mon Sep 17 00:00:00 2001 From: daniel-skopek Date: Sun, 9 Aug 2026 07:13:15 +0200 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20strip=20legacy=20=C2=A7=20codes=20fr?= =?UTF-8?q?om=20[item]=20display=20while=20preserving=20plugin=20style=20c?= =?UTF-8?q?olors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interactivechat/modules/ItemDisplay.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java index 85b563a9..6455a3d7 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java @@ -48,11 +48,14 @@ import net.kyori.adventure.key.Key; import net.kyori.adventure.nbt.api.BinaryTagHolder; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.DataComponentValue; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent.ShowItem; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -66,6 +69,8 @@ import org.bukkit.inventory.meta.ItemMeta; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -211,7 +216,18 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item } String amountString = ""; - Component itemDisplayNameComponent = ItemStackUtils.getDisplayName(item); + Component itemDisplayNameComponent = ItemStackUtils.getDisplayName(item, false); + List flattened = ComponentFlattening.flatten(itemDisplayNameComponent).children(); + List cleaned = new ArrayList<>(flattened.size()); + for (Component child : flattened) { + if (child instanceof TextComponent) { + TextComponent text = (TextComponent) child; + cleaned.add(text.content(ChatColorUtils.stripColor(text.content()))); + } else { + cleaned.add(child); + } + } + itemDisplayNameComponent = ComponentCompacting.optimize(Component.empty().children(cleaned)); amountString = String.valueOf(itemAmount); Key key = ItemNBTUtils.getNMSItemStackNamespacedKey(item); @@ -311,7 +327,15 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item } Component itemDisplayComponent = PlaceholderParser.parse(player, itemAmount == 1 ? InteractiveChat.itemSingularReplaceText : InteractiveChat.itemReplaceText.replaceText(TextReplacementConfig.builder().matchLiteral("{Amount}").replacement(Component.text(amountString)).build())); - itemDisplayComponent = itemDisplayComponent.replaceText(TextReplacementConfig.builder().matchLiteral("{Item}").replacement(itemDisplayNameComponent).build()); + TextColor templateColor = NamedTextColor.WHITE; + for (Component child : ComponentFlattening.flatten(itemDisplayComponent).children()) { + TextColor color = child.color(); + if (color != null) { + templateColor = color; + break; + } + } + itemDisplayComponent = itemDisplayComponent.replaceText(TextReplacementConfig.builder().matchLiteral("{Item}").replacement(itemDisplayNameComponent.colorIfAbsent(templateColor)).build()); if (showHover) { itemDisplayComponent = itemDisplayComponent.hoverEvent(hoverEvent); } else if (alternativeHover != null) { From 80b9dd1cd399adf528ffed8f0d65ddd051e779aa Mon Sep 17 00:00:00 2001 From: daniel-skopek Date: Mon, 10 Aug 2026 07:43:25 +0200 Subject: [PATCH 3/4] Escape MiniMessage tags in item display names to prevent Nexo colorization --- .../loohp/interactivechat/modules/ItemDisplay.java | 12 +++++++++--- .../loohp/interactivechat/utils/ChatColorUtils.java | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java index 6455a3d7..b137f10d 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java @@ -35,6 +35,7 @@ import com.loohp.interactivechat.utils.ComponentCompacting; import com.loohp.interactivechat.utils.ComponentFlattening; import com.loohp.interactivechat.utils.ComponentReplacing; +import com.loohp.interactivechat.utils.ComponentStyling; import com.loohp.interactivechat.utils.ComponentUtils; import com.loohp.interactivechat.utils.FilledMapUtils; import com.loohp.interactivechat.utils.HashUtils; @@ -222,13 +223,18 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item for (Component child : flattened) { if (child instanceof TextComponent) { TextComponent text = (TextComponent) child; - cleaned.add(text.content(ChatColorUtils.stripColor(text.content()))); + cleaned.add(text.content(ChatColorUtils.escapeMiniMessageTags(ChatColorUtils.stripColor(text.content())))); } else { cleaned.add(child); } } itemDisplayNameComponent = ComponentCompacting.optimize(Component.empty().children(cleaned)); + ItemStack hoverItem = (trimmedItem == null ? item : trimmedItem).clone(); + if (itemMeta != null && itemMeta.hasDisplayName()) { + NMS.getInstance().setItemStackDisplayName(hoverItem, ComponentStyling.stripColor(itemDisplayNameComponent)); + } + amountString = String.valueOf(itemAmount); Key key = ItemNBTUtils.getNMSItemStackNamespacedKey(item); @@ -237,12 +243,12 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item if (item.getType().equals(Material.AIR)) { showHover = false; } - Map dataComponents = ItemNBTUtils.getNMSItemStackDataComponents(trimmedItem == null ? item : trimmedItem); + Map dataComponents = ItemNBTUtils.getNMSItemStackDataComponents(hoverItem); dataComponents.remove(Key.key("minecraft", "container")); dataComponents.remove(Key.key("minecraft", "bundle_contents")); showItem = dataComponents.isEmpty() ? ShowItem.showItem(key, itemAmount) : ShowItem.showItem(key, itemAmount, dataComponents); } else { - String tag = ItemNBTUtils.getNMSItemStackTag(trimmedItem == null ? item : trimmedItem); + String tag = ItemNBTUtils.getNMSItemStackTag(hoverItem); showItem = tag == null ? ShowItem.showItem(key, itemAmount) : ShowItem.showItem(key, itemAmount, BinaryTagHolder.binaryTagHolder(tag)); } diff --git a/common/src/main/java/com/loohp/interactivechat/utils/ChatColorUtils.java b/common/src/main/java/com/loohp/interactivechat/utils/ChatColorUtils.java index 9b64330d..fa2bd759 100644 --- a/common/src/main/java/com/loohp/interactivechat/utils/ChatColorUtils.java +++ b/common/src/main/java/com/loohp/interactivechat/utils/ChatColorUtils.java @@ -21,6 +21,7 @@ package com.loohp.interactivechat.utils; import com.loohp.interactivechat.InteractiveChat; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.md_5.bungee.api.ChatColor; import java.util.Arrays; @@ -46,6 +47,10 @@ public static String stripColor(String string) { return string.replaceAll("\u00a7[0-9A-Fa-fk-orx]", ""); } + public static String escapeMiniMessageTags(String string) { + return MiniMessage.miniMessage().escapeTags(string); + } + public static String filterIllegalColorCodes(String string) { return filterIllegalColorCodes(string, com.loohp.interactivechat.InteractiveChat.version.isLegacyRGB()); } From ea0b9d16e748d5f970718a56f63171c896f1b753 Mon Sep 17 00:00:00 2001 From: daniel-skopek Date: Wed, 12 Aug 2026 03:42:18 +0200 Subject: [PATCH 4/4] Fixed rarity colorization in item display names --- .../java/com/loohp/interactivechat/modules/ItemDisplay.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java index b137f10d..0e2a9d1b 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/ItemDisplay.java @@ -31,6 +31,7 @@ import com.loohp.interactivechat.objectholders.ICPlayer; import com.loohp.interactivechat.objectholders.OfflineICPlayer; import com.loohp.interactivechat.utils.ChatColorUtils; +import com.loohp.interactivechat.utils.ColorUtils; import com.loohp.interactivechat.utils.CompassUtils; import com.loohp.interactivechat.utils.ComponentCompacting; import com.loohp.interactivechat.utils.ComponentFlattening; @@ -230,6 +231,11 @@ public static Component createItemDisplay(OfflineICPlayer player, ItemStack item } itemDisplayNameComponent = ComponentCompacting.optimize(Component.empty().children(cleaned)); + ChatColor rarity = NMS.getInstance().getRarityColor(item); + if (rarity != null) { + itemDisplayNameComponent = itemDisplayNameComponent.colorIfAbsent(ColorUtils.toTextColor(rarity)); + } + ItemStack hoverItem = (trimmedItem == null ? item : trimmedItem).clone(); if (itemMeta != null && itemMeta.hasDisplayName()) { NMS.getInstance().setItemStackDisplayName(hoverItem, ComponentStyling.stripColor(itemDisplayNameComponent));