From f17c84b2d75d4c70f17189fc41780238878fa7da Mon Sep 17 00:00:00 2001 From: MrMicky Date: Sat, 6 Jul 2024 16:53:42 +0200 Subject: [PATCH] Optimize reflection --- .../java/fr/mrmicky/fastboard/FastReflection.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/mrmicky/fastboard/FastReflection.java b/src/main/java/fr/mrmicky/fastboard/FastReflection.java index c0f9d03..76b05d8 100644 --- a/src/main/java/fr/mrmicky/fastboard/FastReflection.java +++ b/src/main/java/fr/mrmicky/fastboard/FastReflection.java @@ -45,6 +45,7 @@ public final class FastReflection { private static final MethodType VOID_METHOD_TYPE = MethodType.methodType(void.class); private static final boolean NMS_REPACKAGED = optionalClass(NM_PACKAGE + ".network.protocol.Packet").isPresent(); + private static final boolean MOJANG_MAPPINGS = optionalClass(NM_PACKAGE + ".network.chat.Component").isPresent(); private static volatile Object theUnsafe; @@ -70,18 +71,8 @@ public static Class nmsClass(String post1_17package, String className) throws return Class.forName(nmsClassName(post1_17package, className)); } - public static Class nmsClass(String post1_17package, String spigotClassName, String mojangClassName) throws ClassNotFoundException { - Class clazz; - try { - clazz = Class.forName(nmsClassName(post1_17package, spigotClassName)); - } catch (ClassNotFoundException spigotNotFound) { - try { - clazz = Class.forName(nmsClassName(post1_17package, mojangClassName)); - } catch (ClassNotFoundException mojangNotFound) { - throw new ClassNotFoundException("Class : " + spigotClassName + " / " + mojangClassName + " could not be found"); - } - } - return clazz; + public static Class nmsClass(String post1_17package, String spigotClass, String mojangClass) throws ClassNotFoundException { + return nmsClass(post1_17package, MOJANG_MAPPINGS ? mojangClass : spigotClass); } public static Optional> nmsOptionalClass(String post1_17package, String className) {