add coloring to /geo

sorry for low effort today
This commit is contained in:
Minecon724 2024-06-04 18:22:56 +02:00
parent 883ce366d1
commit 1efd8cb091
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -9,7 +9,9 @@ import org.bukkit.entity.Player;
import eu.m724.realweather.GlobalConstants; import eu.m724.realweather.GlobalConstants;
import eu.m724.wtapi.object.Coordinates; 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.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
public class GeoCommand implements CommandExecutor { public class GeoCommand implements CommandExecutor {
@ -22,8 +24,13 @@ public class GeoCommand implements CommandExecutor {
if (player != null) { if (player != null) {
Location location = player.getLocation(); Location location = player.getLocation();
Coordinates coordinates = GlobalConstants.getMapper().locationToCoordinates(location); 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); player.spigot().sendMessage(component);
} else { } else {
sender.sendMessage("Add arguments to use this command in console"); 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); Coordinates coordinates = new Coordinates(latitude, longitude);
Location location = GlobalConstants.getMapper().coordinatesToLocation(player.getWorld(), coordinates); 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 = new ComponentBuilder("\nPosition: ").color(ChatColor.GOLD)
BaseComponent component = TextComponent.fromLegacy(text); .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); player.spigot().sendMessage(component);
if (args.length == 3) { if (args.length == 3) {