From 8f9c0d141b90216254f6fdc5d108fdc7325a2b4b Mon Sep 17 00:00:00 2001 From: chickeneer Date: Thu, 25 Jan 2024 07:13:04 -0600 Subject: [PATCH] Fix locale reading for non-paper bukkit for 1.20.2+ #405 --- .../aikar/commands/BukkitCommandManager.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/co/aikar/commands/BukkitCommandManager.java b/bukkit/src/main/java/co/aikar/commands/BukkitCommandManager.java index c14e08e35..04e22c578 100755 --- a/bukkit/src/main/java/co/aikar/commands/BukkitCommandManager.java +++ b/bukkit/src/main/java/co/aikar/commands/BukkitCommandManager.java @@ -319,21 +319,26 @@ void readPlayerLocale(Player player) { try { locale = player.locale(); } catch (NoSuchMethodError ignored) { - Field entityField = getEntityField(player); - if (entityField != null) { - Object nmsPlayer = entityField.get(player); - if (nmsPlayer != null) { - Field localeField = nmsPlayer.getClass().getDeclaredField("locale"); - localeField.setAccessible(true); - Object localeString = localeField.get(nmsPlayer); - if (localeString instanceof String) { - if (!localeString.equals(issuersLocaleString.get(player.getUniqueId()))) { - String[] split = ACFPatterns.UNDERSCORE.split((String) localeString); - locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]); - } + Object localeString = null; + try { + localeString = player.getLocale(); + } catch (NoSuchMethodError ignored1) { + Field entityField = getEntityField(player); + if (entityField != null) { + Object nmsPlayer = entityField.get(player); + if (nmsPlayer != null) { + Field localeField = nmsPlayer.getClass().getDeclaredField("locale"); + localeField.setAccessible(true); + localeString = localeField.get(nmsPlayer); } } } + if (localeString instanceof String) { + if (!localeString.equals(issuersLocaleString.get(player.getUniqueId()))) { + String[] split = ACFPatterns.UNDERSCORE.split((String) localeString); + locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]); + } + } } if (locale != null) { UUID playerUniqueId = player.getUniqueId();