Fix IllegalAccessException with advancement listener on 1.12.2 (#4826)

Fixes #4809.
This commit is contained in:
Josh Roy 2022-03-03 15:38:39 -05:00 committed by GitHub
parent c5253bc5e2
commit 1a5526867c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerAdvancementDoneEvent;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
public class AdvancementListenerProvider implements Listener {
private final Object language;
@ -25,10 +26,12 @@ public class AdvancementListenerProvider implements Listener {
} else {
languageClass = ReflUtil.getNMSClass("LocaleLanguage");
}
final MethodHandles.Lookup lookup = MethodHandles.lookup();
//noinspection ConstantConditions
language = lookup.findStatic(languageClass, ReflUtil.isMojMap() ? "getInstance" : "a", MethodType.methodType(languageClass)).invoke();
languageGetOrDefault = lookup.findVirtual(languageClass, ReflUtil.isMojMap() ? "getOrDefault" : "a", MethodType.methodType(String.class, String.class));
final Method iWishICouldUseMethodHandles = languageClass.getDeclaredMethod(ReflUtil.isMojMap() ? "getInstance" : "a");
iWishICouldUseMethodHandles.setAccessible(true);
language = iWishICouldUseMethodHandles.invoke(null);
languageGetOrDefault = MethodHandles.lookup().findVirtual(languageClass, ReflUtil.isMojMap() ? "getOrDefault" : "a", MethodType.methodType(String.class, String.class));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)