From 338b52b0dc299474ad4b820997e38f2cb03b9cec Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sun, 5 Mar 2023 17:46:41 -0500 Subject: [PATCH] Restore legacy server compatibility. Bump version --- pom.xml | 2 +- .../me/pikamug/localelib/LocaleManager.java | 21 ++++++++++++++++--- src/main/resources/plugin.yml | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ee370dc..c9d7611 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ me.pikamug.localelib LocaleLib - 3.1 + 3.2 LocaleLib https://github.com/PikaMug/LocaleLib/ diff --git a/src/main/java/me/pikamug/localelib/LocaleManager.java b/src/main/java/me/pikamug/localelib/LocaleManager.java index 20664d7..79687ca 100644 --- a/src/main/java/me/pikamug/localelib/LocaleManager.java +++ b/src/main/java/me/pikamug/localelib/LocaleManager.java @@ -141,7 +141,7 @@ public boolean sendMessage(final Player player, final String message, final Mate for (final String lk : lvlKeys) { msg = msg.replaceFirst("", translate(msg, lk, "")); } - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]"); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]"); return true; } @@ -193,7 +193,7 @@ public boolean sendMessage(final Player player, final String message, final Map< msg = message.replaceFirst("", translate(message, lk, "")); } } - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]"); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]"); return true; } @@ -215,7 +215,7 @@ public boolean sendMessage(final Player player, final String message, final Enti } final String key = queryEntityType(type, extra); final String msg = message.replace("", translate(message, key, "")); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]"); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]"); return true; } @@ -491,6 +491,21 @@ private String translate(final String message, final String key, final String pl return replacement; } + /** + * Format player name according to server's Bukkit version + * + * @param player Player whose name to format + * @return Formatted name + */ + private String formatName(Player player) { + if (!isBelow113()) { + // Better Geyser/Floodgate compatibility + return "\"" + player.getName() + "\""; + } else { + return player.getName(); + } + } + /** * Checks whether the server's Bukkit version supports use of the ItemMeta#getBasePotionData method. * diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e099b99..89a82e9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: LocaleLib main: me.pikamug.localelib.LocaleLib -version: 3.1 +version: 3.2 api-version: 1.13 description: Show translated names of items, entities & more in client's language website: https://github.com/PikaMug/LocaleLib