From 1efd8cb091cba862ac2ef46833ac7c6a6145c222 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Tue, 4 Jun 2024 18:22:56 +0200 Subject: [PATCH] add coloring to /geo sorry for low effort today --- .../m724/realweather/commands/GeoCommand.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/m724/realweather/commands/GeoCommand.java b/src/main/java/eu/m724/realweather/commands/GeoCommand.java index 29cea71..2578f12 100644 --- a/src/main/java/eu/m724/realweather/commands/GeoCommand.java +++ b/src/main/java/eu/m724/realweather/commands/GeoCommand.java @@ -9,7 +9,9 @@ import org.bukkit.entity.Player; import eu.m724.realweather.GlobalConstants; import eu.m724.wtapi.object.Coordinates; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.TextComponent; public class GeoCommand implements CommandExecutor { @@ -22,8 +24,13 @@ public class GeoCommand implements CommandExecutor { if (player != null) { Location location = player.getLocation(); Coordinates coordinates = GlobalConstants.getMapper().locationToCoordinates(location); - String text = String.format("Position: %f %f %f\nGeolocation: %f %f", location.getX(), location.getY(), location.getZ(), coordinates.latitude, coordinates.longitude); - BaseComponent component = TextComponent.fromLegacy(text); // TODO add color + + BaseComponent[] component = new ComponentBuilder("\nGeolocation: ").color(ChatColor.GOLD) + .append(String.format("lat: %f, lon: %f\n", coordinates.latitude, coordinates.longitude)).color(ChatColor.AQUA) + .append("Position: ").color(ChatColor.GRAY) + .append(String.format("x: %f, z: %f\n", location.getX(), location.getZ())).color(ChatColor.DARK_AQUA) + .create(); // TODO improve readability + player.spigot().sendMessage(component); } else { sender.sendMessage("Add arguments to use this command in console"); @@ -35,8 +42,12 @@ public class GeoCommand implements CommandExecutor { Coordinates coordinates = new Coordinates(latitude, longitude); Location location = GlobalConstants.getMapper().coordinatesToLocation(player.getWorld(), coordinates); - String text = String.format("Position: %f %f %f\nGeolocation: %f %f", location.getX(), location.getY(), location.getZ(), coordinates.latitude, coordinates.longitude); - BaseComponent component = TextComponent.fromLegacy(text); + BaseComponent[] component = new ComponentBuilder("\nPosition: ").color(ChatColor.GOLD) + .append(String.format("x: %f, z: %f\n", location.getX(), location.getZ())).color(ChatColor.AQUA) + .append("Geolocation: ").color(ChatColor.GRAY) + .append(String.format("lat: %f, lon: %f\n", coordinates.latitude, coordinates.longitude)).color(ChatColor.DARK_AQUA) + .create(); + player.spigot().sendMessage(component); if (args.length == 3) {