Cleanup reflection
This commit is contained in:
parent
4e54d86712
commit
e8010782fd
@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class I18NUtils {
|
public class I18NUtils {
|
||||||
|
|
||||||
private static Method spigotMethod;
|
private static Method spigotGetLocale;
|
||||||
private static final List<String> LOCALE_LIST = Arrays.asList(
|
private static final List<String> LOCALE_LIST = Arrays.asList(
|
||||||
"en", "bg", "de", "eo", "es", "et", "eu", "fi", "fr", "gl", "hu", "id", "it", "ja", "ko", "lt", "nl", "pl",
|
"en", "bg", "de", "eo", "es", "et", "eu", "fi", "fr", "gl", "hu", "id", "it", "ja", "ko", "lt", "nl", "pl",
|
||||||
"pt", "ro", "ru", "sk", "sr", "tr", "uk"
|
"pt", "ro", "ru", "sk", "sr", "tr", "uk"
|
||||||
@ -19,9 +19,10 @@ public class I18NUtils {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
spigotMethod = Player.class.getMethod("spigot");
|
spigotGetLocale = Player.Spigot.class.getMethod("getLocale");
|
||||||
|
spigotGetLocale.setAccessible(true);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
spigotMethod = null;
|
spigotGetLocale = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,11 +36,7 @@ public class I18NUtils {
|
|||||||
return player.getLocale().toLowerCase();
|
return player.getLocale().toLowerCase();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Object spigot = spigotMethod.invoke(player);
|
return ((String) spigotGetLocale.invoke(player.spigot())).toLowerCase();
|
||||||
Method spigotGetLocaleMethod = spigot.getClass().getMethod("getLocale");
|
|
||||||
spigotGetLocaleMethod.setAccessible(true);
|
|
||||||
|
|
||||||
return ((String) spigotGetLocaleMethod.invoke(spigot)).toLowerCase();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user