Skip to content

Commit

Permalink
Fix IllegalAccessException with advancement listener on 1.12.2 (#4826)
Browse files Browse the repository at this point in the history
Fixes #4809.
  • Loading branch information
JRoy authored Mar 3, 2022
1 parent c5253bc commit 1a55268
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand All @@ -25,10 +26,12 @@ public AdvancementListenerProvider() throws Throwable {
} 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)
Expand Down

0 comments on commit 1a55268

Please sign in to comment.