Added tooltips for clickable commands in lookup results

This commit is contained in:
Intelli 2022-02-03 20:36:27 -07:00
parent 2c8e289c43
commit 70f74ced0f
5 changed files with 62 additions and 6 deletions

View File

@ -45,7 +45,12 @@ public class SpigotAdapter implements SpigotInterface {
} }
@Override @Override
public void setHoverComponent(Object message, String[] data) { public void addHoverComponent(Object message, String[] data) {
return;
}
@Override
public void setHoverEvent(Object message, String text) {
return; return;
} }

View File

@ -16,7 +16,7 @@ public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
public static ChatColor DARK_AQUA = ChatColor.DARK_AQUA; public static ChatColor DARK_AQUA = ChatColor.DARK_AQUA;
@Override @Override
public void setHoverComponent(Object message, String[] data) { public void addHoverComponent(Object message, String[] data) {
((TextComponent) message).addExtra(data[2]); ((TextComponent) message).addExtra(data[2]);
} }
@ -41,10 +41,11 @@ public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
if (data[0].equals(Chat.COMPONENT_COMMAND)) { if (data[0].equals(Chat.COMPONENT_COMMAND)) {
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2])); TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, data[1])); component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, data[1]));
SpigotAdapter.ADAPTER.setHoverEvent(component, Util.hoverCommandFilter(data[1]));
message.addExtra(component); message.addExtra(component);
} }
else if (data[0].equals(Chat.COMPONENT_POPUP)) { else if (data[0].equals(Chat.COMPONENT_POPUP)) {
SpigotAdapter.ADAPTER.setHoverComponent(message, data); SpigotAdapter.ADAPTER.addHoverComponent(message, data);
} }
} }
else { else {

View File

@ -4,7 +4,9 @@ import org.bukkit.command.CommandSender;
public interface SpigotInterface { public interface SpigotInterface {
public void setHoverComponent(Object message, String[] data); public void addHoverComponent(Object message, String[] data);
public void setHoverEvent(Object message, String text);
public void sendComponent(CommandSender sender, String string, String bypass); public void sendComponent(CommandSender sender, String string, String bypass);

View File

@ -15,7 +15,7 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
} }
@Override @Override
public void setHoverComponent(Object message, String[] data) { public void addHoverComponent(Object message, String[] data) {
try { try {
if (Config.getGlobal().HOVER_EVENTS) { if (Config.getGlobal().HOVER_EVENTS) {
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2])); TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
@ -23,7 +23,7 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
((TextComponent) message).addExtra(component); ((TextComponent) message).addExtra(component);
} }
else { else {
super.setHoverComponent(message, data); super.addHoverComponent(message, data);
} }
} }
catch (Exception e) { catch (Exception e) {
@ -31,4 +31,11 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
} }
} }
@Override
public void setHoverEvent(Object component, String text) {
if (Config.getGlobal().HOVER_EVENTS) {
((TextComponent) component).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(text))));
}
}
} }

View File

@ -185,6 +185,47 @@ public class Util extends Queue {
return message.toString(); return message.toString();
} }
public static String hoverCommandFilter(String string) {
StringBuilder command = new StringBuilder();
String[] data = string.toLowerCase().split(" ");
if (data.length > 2) {
if (data[1].equals("l")) {
data[1] = "page";
}
if (data[2].startsWith("wid:")) {
String nameWid = data[2].replaceFirst("wid:", "");
if (nameWid.length() > 0 && nameWid.equals(nameWid.replaceAll("[^0-9]", ""))) {
nameWid = Util.getWorldName(Integer.parseInt(nameWid));
if (nameWid.length() > 0) {
data[2] = nameWid;
}
}
}
if (data[1].equals("teleport") && data.length > 5) {
data[3] = Integer.toString((int) (Double.parseDouble(data[3]) - 0.50));
data[4] = Integer.toString(Integer.parseInt(data[4]));
data[5] = Integer.toString((int) (Double.parseDouble(data[5]) - 0.50));
}
}
for (String s : data) {
if (s.isEmpty()) {
continue;
}
if (command.length() > 0) {
command.append(" ");
}
command.append(s);
}
return command.toString();
}
public static String capitalize(String string, boolean allWords) { public static String capitalize(String string, boolean allWords) {
if (string == null || string.isEmpty()) { if (string == null || string.isEmpty()) {
return string; return string;