diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveLevelEntityPlayerLatencyFieldMethod.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveLevelEntityPlayerLatencyFieldMethod.java index 18f97269e..979bc345e 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveLevelEntityPlayerLatencyFieldMethod.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveLevelEntityPlayerLatencyFieldMethod.java @@ -38,7 +38,7 @@ public class ReflectiveLevelEntityPlayerLatencyFieldMethod implements PingMethod private static void setMethods() throws IllegalAccessException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { MethodHandle[] methodHandles = PingMethodReflection.getMethods( Reflection.getCraftBukkitClass("entity.CraftPlayer"), - Class.forName("net.minecraft.server.level.EntityPlayer"), + getEntityPlayer(), "getHandle", "latency" ); @@ -46,6 +46,14 @@ public class ReflectiveLevelEntityPlayerLatencyFieldMethod implements PingMethod pingField = methodHandles[1]; } + private static Class getEntityPlayer() throws ClassNotFoundException { + try { + return Class.forName("net.minecraft.server.level.EntityPlayer"); + } catch (NullPointerException classLoaderError) { + throw new ClassNotFoundException("net.minecraft.server.level.EntityPlayer"); + } + } + @Override public boolean isAvailable() { try { diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveUnmappedLatencyFieldMethod.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveUnmappedLatencyFieldMethod.java index a530e78cb..381204bc0 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveUnmappedLatencyFieldMethod.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/timed/ReflectiveUnmappedLatencyFieldMethod.java @@ -38,7 +38,7 @@ public class ReflectiveUnmappedLatencyFieldMethod implements PingMethod { private static void setMethods() throws IllegalAccessException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { MethodHandle[] methodHandles = PingMethodReflection.getMethods( Reflection.getCraftBukkitClass("entity.CraftPlayer"), - Class.forName("net.minecraft.server.level.EntityPlayer"), + getEntityPlayer(), "getHandle", "e" ); @@ -46,6 +46,14 @@ public class ReflectiveUnmappedLatencyFieldMethod implements PingMethod { pingField = methodHandles[1]; } + private static Class getEntityPlayer() throws ClassNotFoundException { + try { + return Class.forName("net.minecraft.server.level.EntityPlayer"); + } catch (NullPointerException classLoaderError) { + throw new ClassNotFoundException("net.minecraft.server.level.EntityPlayer"); + } + } + @Override public boolean isAvailable() { try { diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/utilities/java/Reflection.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/utilities/java/Reflection.java index 09a65d55c..314b89355 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/utilities/java/Reflection.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/utilities/java/Reflection.java @@ -140,7 +140,7 @@ public final class Reflection { private static Class getCanonicalClass(String canonicalName) { try { return Class.forName(canonicalName); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException | NullPointerException e) { throw new IllegalArgumentException("Cannot find " + canonicalName, e); } }