Skip to content

Commit

Permalink
Fixed obfuscation in item names making tooltips unreadable (fixes #487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed May 10, 2024
1 parent 48d2030 commit 3b9d872
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/main/java/net/coreprotect/spigot/Spigot_v1_16.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -18,8 +19,46 @@ public Spigot_v1_16() {
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 {
Expand Down

0 comments on commit 3b9d872

Please sign in to comment.