From 3b9d8726d9aa80e3400783cd2c3a6571390be5ad Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 9 May 2024 22:44:29 -0600 Subject: [PATCH] Fixed obfuscation in item names making tooltips unreadable (fixes #487) --- .../net/coreprotect/spigot/Spigot_v1_16.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/coreprotect/spigot/Spigot_v1_16.java b/src/main/java/net/coreprotect/spigot/Spigot_v1_16.java index 29395d2..d45c967 100644 --- a/src/main/java/net/coreprotect/spigot/Spigot_v1_16.java +++ b/src/main/java/net/coreprotect/spigot/Spigot_v1_16.java @@ -3,6 +3,7 @@ package net.coreprotect.spigot; import net.coreprotect.config.Config; import net.coreprotect.utility.Color; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.hover.content.Text; @@ -18,8 +19,46 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface { public void addHoverComponent(Object message, String[] data) { try { if (Config.getGlobal().HOVER_EVENTS) { + String tooltipText = data[1]; // text displayed inside tooltip TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2])); - component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(processComponent(data[1]))))); + // BaseComponent[] displayComponent = TextComponent.fromLegacyText(processComponent(tooltipText)); + + if (tooltipText.contains(Color.MAGIC)) { + tooltipText = tooltipText.replace(Color.MAGIC, ""); + + // to-do + /* + ComponentBuilder formattedComponent = new ComponentBuilder(); + StringBuilder messageTest = new StringBuilder(); + String colorChar = String.valueOf(ChatColor.COLOR_CHAR); + boolean isObfuscated = false; + + String[] tooltip = tooltipText.split(colorChar); + for (String splitText : tooltip) { + boolean setObfuscated = splitText.startsWith("k"); + splitText = setObfuscated ? splitText.substring(1) : (splitText.length() > 0 ? colorChar : "") + splitText; + if ((setObfuscated && !isObfuscated) || (!setObfuscated && isObfuscated)) { + formattedComponent.append(TextComponent.fromLegacyText(processComponent(messageTest.toString()))); + formattedComponent.obfuscated(false); // setObfuscated + formattedComponent.append(TextComponent.fromLegacyText(processComponent(splitText))); + messageTest.setLength(0); + isObfuscated = !isObfuscated; + } + else { + messageTest.append(splitText); + } + } + + if (messageTest.length() > 0) { + formattedComponent.append(TextComponent.fromLegacyText(processComponent(messageTest.toString()))); + } + + displayComponent = formattedComponent.create(); + */ + } + + BaseComponent[] displayComponent = TextComponent.fromLegacyText(processComponent(tooltipText)); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(displayComponent))); ((TextComponent) message).addExtra(component); } else {