From a6441d765cb3fbff719a1c48f80ef9bd1213803b Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 23 Aug 2022 21:20:32 -0400 Subject: [PATCH] pop review --- .../earth2me/essentials/ProviderFactory.java | 27 +++++++++---------- .../providers/FlatSpawnEggProvider.java | 2 +- .../providers/ReflDataWorldInfoProvider.java | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java b/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java index 5081d1728f8..8cd87677fcd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java @@ -52,20 +52,10 @@ public void finalizeRegistration() { Class highestProvider = null; ProviderData highestProviderData = null; int highestWeight = -1; - providerLoop: for (final Class provider : entry.getValue()) { try { final ProviderData providerData = provider.getAnnotation(ProviderData.class); - if (providerData.weight() > highestWeight) { - for (final Method method : provider.getMethods()) { - if (method.isAnnotationPresent(ProviderTest.class)) { - final Boolean result = (Boolean) method.invoke(null); - if (!result) { - continue providerLoop; - } - } - } - + if (providerData.weight() > highestWeight && testProvider(provider)) { highestWeight = providerData.weight(); highestProvider = provider; highestProviderData = providerData; @@ -84,12 +74,21 @@ public void finalizeRegistration() { registeredProviders.clear(); } - private C getProviderInstance(final Class provider) { + private boolean testProvider(final Class providerClass) throws InvocationTargetException, IllegalAccessException { + for (final Method method : providerClass.getMethods()) { + if (method.isAnnotationPresent(ProviderTest.class)) { + return (Boolean) method.invoke(null); + } + } + return true; + } + + private

P getProviderInstance(final Class

provider) { try { final Constructor constructor = provider.getConstructors()[0]; if (constructor.getParameterTypes().length == 0) { //noinspection unchecked - return (C) constructor.newInstance(); + return (P) constructor.newInstance(); } final Object[] args = new Object[constructor.getParameterTypes().length]; @@ -105,7 +104,7 @@ private C getProviderInstance(final Class provider) { } //noinspection unchecked - return (C) constructor.newInstance(args); + return (P) constructor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { try { return provider.getConstructor().newInstance(); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java index 8bf50aa5011..2240cce8a9c 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java @@ -28,7 +28,7 @@ public EntityType getSpawnedType(final ItemStack eggItem) throws IllegalArgument public static boolean test() { try { //noinspection unused - final Material yourMother = Material.COW_SPAWN_EGG; + final Material itMakesMeDeclareAVariable = Material.COW_SPAWN_EGG; return true; } catch (final Throwable ignored) { return false; diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java index 9f0e03d503b..145a8983c17 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java @@ -29,7 +29,7 @@ public int getMinHeight(World world) { @ProviderTest public static boolean test() { - // troll face + // TODO: THIS IS INCORRECT return false; } }