From 1a5526867cf4767f9f012168b2aa16eb7e1b5460 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 3 Mar 2022 15:38:39 -0500 Subject: [PATCH] Fix IllegalAccessException with advancement listener on 1.12.2 (#4826) Fixes #4809. --- .../nms/refl/providers/AdvancementListenerProvider.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/AdvancementListenerProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/AdvancementListenerProvider.java index c1745e515..f8c45c57d 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/AdvancementListenerProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/AdvancementListenerProvider.java @@ -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)