Skip to content

Commit

Permalink
Fix locale reading for non-paper bukkit for 1.20.2+ aikar#405
Browse files Browse the repository at this point in the history
  • Loading branch information
chickeneer committed Jan 25, 2024
1 parent 26d72f2 commit 8f9c0d1
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions bukkit/src/main/java/co/aikar/commands/BukkitCommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8f9c0d1

Please sign in to comment.