mirror of
https://github.com/aikar/commands.git
synced 2026-06-12 19:10:37 +00:00
Use the player locale api instead of reflection to fix issues #402
This commit is contained in:
@@ -315,33 +315,34 @@ public class BukkitCommandManager extends CommandManager<
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Field entityField = getEntityField(player);
|
||||
if (entityField == null) {
|
||||
return;
|
||||
}
|
||||
Object nmsPlayer = entityField.get(player);
|
||||
if (nmsPlayer != null) {
|
||||
Field localeField;
|
||||
try {
|
||||
localeField = nmsPlayer.getClass().getDeclaredField("locale");
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
localeField = nmsPlayer.getClass().getDeclaredField("language");
|
||||
}
|
||||
localeField.setAccessible(true);
|
||||
Object localeString = localeField.get(nmsPlayer);
|
||||
if (localeString instanceof String) {
|
||||
UUID playerUniqueId = player.getUniqueId();
|
||||
if (!localeString.equals(issuersLocaleString.get(playerUniqueId))) {
|
||||
String[] split = ACFPatterns.UNDERSCORE.split((String) localeString);
|
||||
Locale locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]);
|
||||
Locale prev = issuersLocale.put(playerUniqueId, locale);
|
||||
issuersLocaleString.put(playerUniqueId, (String) localeString);
|
||||
if (!Objects.equals(locale, prev)) {
|
||||
this.notifyLocaleChange(getCommandIssuer(player), prev, locale);
|
||||
Locale locale = null;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (locale != null) {
|
||||
UUID playerUniqueId = player.getUniqueId();
|
||||
Locale prev = issuersLocale.put(playerUniqueId, locale);
|
||||
issuersLocaleString.put(playerUniqueId, locale.toString());
|
||||
if (!Objects.equals(locale, prev)) {
|
||||
this.notifyLocaleChange(getCommandIssuer(player), prev, locale);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
cantReadLocale = true;
|
||||
this.scheduler.cancelLocaleTask();
|
||||
|
||||
Reference in New Issue
Block a user