From 9a596a5af9c2b27e3d23566248043fd0c64a2598 Mon Sep 17 00:00:00 2001 From: FireInstall Date: Fri, 3 May 2024 14:34:54 +0200 Subject: [PATCH] update use textComponents, since we rely on paper anyway --- pom.xml | 10 ++++++ .../java/de/minebench/syncinv/SyncInv.java | 31 +++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 29c7428..0413ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,12 @@ 6.2.3.RELEASE compile + + de.themoep + minedown-adventure + 1.7.1-SNAPSHOT + compile + @@ -134,6 +140,10 @@ org.reactivestreams de.minebench.syncinv.lib.reactivestreams + + de.themoep.minedown + de.minebench.syncinv.lib.minedown + diff --git a/src/main/java/de/minebench/syncinv/SyncInv.java b/src/main/java/de/minebench/syncinv/SyncInv.java index 2374af9..a0477ce 100644 --- a/src/main/java/de/minebench/syncinv/SyncInv.java +++ b/src/main/java/de/minebench/syncinv/SyncInv.java @@ -16,8 +16,10 @@ import de.minebench.syncinv.messenger.PlayerDataQuery; import de.minebench.syncinv.messenger.RedisMessenger; import de.minebench.syncinv.messenger.ServerMessenger; +import de.themoep.minedown.adventure.MineDown; import lombok.Getter; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.GameRule; import org.bukkit.Location; import org.bukkit.Material; @@ -225,16 +227,16 @@ public void onEnable() { if (query.getYoungestServer() == null) { openInvCommand.onCommand(sender, command, label, args); } else { - sender.sendMessage(ChatColor.RED + "Current server does not have newest player data! " - + ChatColor.GRAY + "Connecting to server " + query.getYoungestServer() + " which has the newest data..."); + sender.sendMessage(Component.text("Current server does not have newest player data! ", NamedTextColor.RED). + append(Component.text("Connecting to server " + query.getYoungestServer() + " which has the newest data...", NamedTextColor.GRAY))); connectToServer(((Player) sender).getUniqueId(), query.getYoungestServer()); } }); if (q == null) { - sender.sendMessage(ChatColor.RED + "Could not query information from other servers! Take a look at the log for more details."); + sender.sendMessage(Component.text("Could not query information from other servers! Take a look at the log for more details.", NamedTextColor.RED)); } } else { - sender.sendMessage(ChatColor.RED + "Player not found!"); + sender.sendMessage(Component.text("Player not found!", NamedTextColor.RED)); } }); return true; @@ -388,11 +390,11 @@ && getConfig().contains("sync-" + syncType.getKey(), true)) { } } - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args) { if (args.length > 0) { if ("reload".equalsIgnoreCase(args[0]) && sender.hasPermission("syncing.command.reload")) { loadConfig(); - sender.sendMessage(ChatColor.YELLOW + "Config reloaded!"); + sender.sendMessage(Component.text("Config reloaded!", NamedTextColor.YELLOW)); return true; } } @@ -401,16 +403,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String /** * Get a language message from the config and replace variables in it - * @param key The key of the message (lang.) - * @param replacements An array of variables to be replaced with certain strings in the format [var,repl,var,repl,...] + * @param key The key of the message (lang.) + * @param replacements An array of String to replace placeholders (uses the % character as placeholder indicators (suffix and prefix)) * @return The message string with colorcodes and variables replaced */ - public String getLang(String key, String... replacements) { - String msg = ChatColor.translateAlternateColorCodes('&', getConfig().getString("lang." + key, getName() + ": &cMissing language key &6" + key)); - for (int i = 0; i + 1 < replacements.length; i += 2) { - msg = msg.replace("%" + replacements[i] + "%", replacements[i+1]); - } - return msg; + public Component getLang(String key, String... replacements) { + String rawMsg = getConfig().getString("lang." + key, getName() + ": Missing language key " + key+""); + return MineDown.parse(rawMsg, replacements); } /** @@ -1132,7 +1131,7 @@ public void kick(UUID playerId, String key) { runSync(() -> { Player player = getServer().getPlayer(playerId); if (player != null) { - player.kickPlayer(getLang(key)); + player.kick(getLang(key)); } }); }