From 81faece9599c176ed90698a3293fac6af34af4ba Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 23 Jun 2022 18:48:46 +0200 Subject: [PATCH] Trying better error management on NMSReflect initialization --- .../lib/paper/reflect/NMSReflect.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 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 8461374..2ee9338 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 @@ -92,13 +92,25 @@ public class NMSReflect { if (IS_SERVER_OBFUSCATED == null) { CLASSES_BY_MOJ.clear(); CLASSES_BY_OBF.clear(); - throw exIfUnableToDetermine; + throw new IllegalStateException("Unable to determine if this server is obfuscated or not", exIfUnableToDetermine); } - + + ClassNotFoundException exIfUnableToGetInstanceClass = null; for (ClassMapping clazz : mappings) { - clazz.cacheReflectClass(); + try { + clazz.cacheReflectClass(); + } catch (ClassNotFoundException e) { + if (exIfUnableToGetInstanceClass == null) + exIfUnableToGetInstanceClass = e; + else { + exIfUnableToGetInstanceClass.addSuppressed(e); + } + } } + + if (exIfUnableToGetInstanceClass != null) + 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); } @@ -111,9 +123,7 @@ public class NMSReflect { * @throws ClassNotFoundException if there is a mapping, but the runtime class was not found. */ public static ClassMapping mojClass(String mojName) throws ClassNotFoundException { - ClassMapping cm = Objects.requireNonNull(CLASSES_BY_MOJ.get(mojName), "Unable to find the Mojang mapped class '" + mojName + "'"); - cm.cacheReflectClass(); - return cm; + return Objects.requireNonNull(CLASSES_BY_MOJ.get(mojName), "Unable to find the Mojang mapped class '" + mojName + "'"); }