From e3ba15e027bd67c6a0e700b58d294e437152a51d Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 23 Jun 2022 19:04:31 +0200 Subject: [PATCH] Trying something else on NMSReflect init --- .../fr/pandacube/lib/paper/reflect/NMSReflect.java | 12 +++++++++--- .../pandacube/lib/paper/reflect/ReflectRegistry.java | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java index 2ee9338..4a785fa 100644 --- a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java +++ b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java @@ -41,9 +41,15 @@ public class NMSReflect { private static Boolean IS_SERVER_OBFUSCATED; + private static boolean isInit = false; - static { + static void init() { + synchronized (NMSReflect.class) { + if (isInit) + return; + isInit = true; + } try { ReflectClass obfHelperClass; @@ -90,8 +96,6 @@ public class NMSReflect { } if (IS_SERVER_OBFUSCATED == null) { - CLASSES_BY_MOJ.clear(); - CLASSES_BY_OBF.clear(); throw new IllegalStateException("Unable to determine if this server is obfuscated or not", exIfUnableToDetermine); } @@ -113,6 +117,8 @@ public class NMSReflect { throw exIfUnableToGetInstanceClass; } catch (Throwable t) { Log.severe("[NMSReflect] The plugin will not be able to access NMS stuff because the obfuscation mapping couldn't be loaded.", t); + CLASSES_BY_MOJ.clear(); + CLASSES_BY_OBF.clear(); } } diff --git a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java index aa4f68c..f7bff46 100644 --- a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java +++ b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java @@ -471,6 +471,7 @@ public class ReflectRegistry { */ public static void init() { + NMSReflect.init(); initRecursively(ReflectRegistry.class); }