mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Use MethodHandle API
This commit is contained in:
@@ -28,6 +28,9 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLocaleChangeEvent;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
@@ -35,6 +38,7 @@ import java.util.Locale;
|
||||
class ACFBukkitLocalesListener implements Listener {
|
||||
|
||||
private final BukkitCommandManager manager;
|
||||
private MethodHandle localeMethod1_8 = null;
|
||||
|
||||
ACFBukkitLocalesListener(BukkitCommandManager manager) {
|
||||
this.manager = manager;
|
||||
@@ -56,13 +60,24 @@ class ACFBukkitLocalesListener implements Listener {
|
||||
}
|
||||
} catch (NoSuchMethodError ignored2) {
|
||||
try {
|
||||
Method getNewLocale = event.getClass().getMethod("getNewLocale");
|
||||
getNewLocale.setAccessible(true);
|
||||
String value = (String) getNewLocale.invoke(event);
|
||||
if (localeMethod1_8 != null) {
|
||||
String value = (String) localeMethod1_8.invoke(event);
|
||||
if (!value.equals(manager.issuersLocaleString.get(player.getUniqueId()))) {
|
||||
locale = ACFBukkitUtil.stringToLocale(value);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
MethodType type = MethodType.methodType(String.class);
|
||||
|
||||
localeMethod1_8 = lookup.findVirtual(PlayerLocaleChangeEvent.class, "getNewLocale", type);
|
||||
String value = (String) localeMethod1_8.invoke(event);
|
||||
if (!value.equals(manager.issuersLocaleString.get(player.getUniqueId()))) {
|
||||
locale = ACFBukkitUtil.stringToLocale(value);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored3) {
|
||||
} catch (Throwable ignored3) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user