mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-25 12:25:37 +01:00
Added tooltips for clickable commands in lookup results
This commit is contained in:
parent
2c8e289c43
commit
70f74ced0f
@ -45,7 +45,12 @@ public class SpigotAdapter implements SpigotInterface {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
|
||||
public static ChatColor DARK_AQUA = ChatColor.DARK_AQUA;
|
||||
|
||||
@Override
|
||||
public void setHoverComponent(Object message, String[] data) {
|
||||
public void addHoverComponent(Object message, String[] data) {
|
||||
((TextComponent) message).addExtra(data[2]);
|
||||
}
|
||||
|
||||
@ -41,10 +41,11 @@ public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
|
||||
if (data[0].equals(Chat.COMPONENT_COMMAND)) {
|
||||
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, data[1]));
|
||||
SpigotAdapter.ADAPTER.setHoverEvent(component, Util.hoverCommandFilter(data[1]));
|
||||
message.addExtra(component);
|
||||
}
|
||||
else if (data[0].equals(Chat.COMPONENT_POPUP)) {
|
||||
SpigotAdapter.ADAPTER.setHoverComponent(message, data);
|
||||
SpigotAdapter.ADAPTER.addHoverComponent(message, data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -4,7 +4,9 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoverComponent(Object message, String[] data) {
|
||||
public void addHoverComponent(Object message, String[] data) {
|
||||
try {
|
||||
if (Config.getGlobal().HOVER_EVENTS) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
super.setHoverComponent(message, data);
|
||||
super.addHoverComponent(message, data);
|
||||
}
|
||||
}
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -185,6 +185,47 @@ public class Util extends Queue {
|
||||
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) {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return string;
|
||||
|
Loading…
Reference in New Issue
Block a user