Use component

This commit is contained in:
Minecon724 2025-04-06 11:29:50 +02:00
commit 41583939ac
Signed by: Minecon724
GPG key ID: A02E6E67AB961189

View file

@ -9,6 +9,12 @@ package eu.m724.tweaks.module.wordcoords;
import eu.m724.tweaks.Language;
import eu.m724.tweaks.module.TweaksModule;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -79,14 +85,34 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
if (encode) {
words = converter.encode(x, z);
String encoded = "///" + String.join(".", words);
sender.sendMessage("%d, %d encodes to ///%s".formatted(x, z, String.join(".", words)));
BaseComponent[] components = new ComponentBuilder()
.append(String.format("%d, %d encodes to ", x, z))
.color(ChatColor.GRAY)
.append(encoded)
.color(ChatColor.AQUA) // TODO improve color
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, encoded))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to copy")))
.create();
sender.spigot().sendMessage(components);
} else {
int[] xz = converter.decode(words);
x = xz[0];
z = xz[1];
sender.sendMessage("///%s decodes to around %d, %d".formatted(String.join(".", words), x, z));
String encoded = "///" + String.join(".", words);
BaseComponent[] components = new ComponentBuilder()
.append(encoded + " decodes to ")
.color(ChatColor.GRAY)
.append("%d, %d".formatted(x, z))
.color(ChatColor.AQUA) // TODO improve color
.append("±8")
.color(ChatColor.GRAY)
.create();
sender.spigot().sendMessage(components);
}
return true;