diff --git a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/CraftBukkitFacet.java b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/CraftBukkitFacet.java index 9d23d2b4..ad377868 100644 --- a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/CraftBukkitFacet.java +++ b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/CraftBukkitFacet.java @@ -160,7 +160,7 @@ public boolean isSupported() { } } } - playerConnectionSendPacket = searchMethod(playerConnectionClass, new int[]{Modifier.PUBLIC}, new String[]{"sendPacket", "send"}, void.class, packetClass); + playerConnectionSendPacket = searchMethod(playerConnectionClass, Modifier.PUBLIC, new String[]{"sendPacket", "send"}, void.class, packetClass); } catch (final Throwable error) { logError(error, "Failed to initialize CraftBukkit sendPacket"); } @@ -396,7 +396,7 @@ static class EntitySound extends PacketFacet implements Facet.EntitySoun private static final MethodHandle NEW_CLIENTBOUND_CUSTOM_SOUND = findConstructor(CLASS_CLIENTBOUND_CUSTOM_SOUND, CLASS_RESOURCE_LOCATION, CLASS_SOUND_SOURCE, CLASS_VEC3, float.class, float.class); private static final MethodHandle NEW_VEC3 = findConstructor(CLASS_VEC3, double.class, double.class, double.class); private static final MethodHandle NEW_RESOURCE_LOCATION = findConstructor(CLASS_RESOURCE_LOCATION, String.class, String.class); - private static final MethodHandle REGISTRY_GET_OPTIONAL = searchMethod(CLASS_REGISTRY, new int[]{Modifier.PUBLIC}, "getOptional", Optional.class, CLASS_RESOURCE_LOCATION); + private static final MethodHandle REGISTRY_GET_OPTIONAL = searchMethod(CLASS_REGISTRY, Modifier.PUBLIC, "getOptional", Optional.class, CLASS_RESOURCE_LOCATION); private static final MethodHandle SOUND_SOURCE_GET_NAME; private static final Object REGISTRY_SOUND_EVENT; @@ -807,7 +807,7 @@ public InputStream toInputStream() { findMcClassName("world.item.ItemStack") ); - private static final MethodHandle MC_ITEMSTACK_SET_TAG = searchMethod(CLASS_MC_ITEMSTACK, new int[]{Modifier.PUBLIC}, "setTag", void.class, CLASS_NBT_TAG_COMPOUND); + private static final MethodHandle MC_ITEMSTACK_SET_TAG = searchMethod(CLASS_MC_ITEMSTACK, Modifier.PUBLIC, "setTag", void.class, CLASS_NBT_TAG_COMPOUND); private static final MethodHandle CRAFT_ITEMSTACK_NMS_COPY = findStaticMethod(CLASS_CRAFT_ITEMSTACK, "asNMSCopy", CLASS_MC_ITEMSTACK, ItemStack.class); private static final MethodHandle CRAFT_ITEMSTACK_CRAFT_MIRROR = findStaticMethod(CLASS_CRAFT_ITEMSTACK, "asCraftMirror", CLASS_CRAFT_ITEMSTACK, CLASS_MC_ITEMSTACK); diff --git a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftReflection.java b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftReflection.java index 0b860481..c582d24a 100644 --- a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftReflection.java +++ b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftReflection.java @@ -146,27 +146,27 @@ public static boolean hasClass(final @NotNull String... classNames) { * Search a handle for a class method. * * @param holderClass a class - * @param methodModifiers method modifiers + * @param modifier method modifiers * @param methodName a method name * @param returnClass a method return class * @param parameterClasses an array of method parameter classes * @return a method handle or {@code null} if not found */ - public static MethodHandle searchMethod(final @Nullable Class holderClass, final @Nullable int[] methodModifiers, final String methodName, final @Nullable Class returnClass, final Class... parameterClasses) { - return searchMethod(holderClass, methodModifiers, new String[] {methodName}, returnClass, parameterClasses); + public static MethodHandle searchMethod(final @Nullable Class holderClass, final @Nullable Integer modifier, final String methodName, final @Nullable Class returnClass, final Class... parameterClasses) { + return searchMethod(holderClass, modifier, new String[] {methodName}, returnClass, parameterClasses); } /** * Search a handle for a class method. * * @param holderClass a class - * @param methodModifiers method modifiers + * @param modifier method modifiers * @param methodNames a method names * @param returnClass a method return class * @param parameterClasses an array of method parameter classes * @return a method handle or {@code null} if not found */ - public static MethodHandle searchMethod(final @Nullable Class holderClass, final @Nullable int[] methodModifiers, final @Nullable String@NotNull[] methodNames, final @Nullable Class returnClass, final Class... parameterClasses) { + public static MethodHandle searchMethod(final @Nullable Class holderClass, final @Nullable Integer modifier, final @Nullable String@NotNull[] methodNames, final @Nullable Class returnClass, final Class... parameterClasses) { if (holderClass == null || returnClass == null) return null; for (final Class parameterClass : parameterClasses) { if (parameterClass == null) return null; @@ -181,7 +181,7 @@ public static MethodHandle searchMethod(final @Nullable Class holderClass, fi } for (final Method method : holderClass.getDeclaredMethods()) { - if (!matchModifiers(method.getModifiers(), methodModifiers) + if ((modifier == null || (method.getModifiers() & modifier) == 0) || !Arrays.equals(method.getParameterTypes(), parameterClasses)) continue; try { return LOOKUP.findVirtual(holderClass, method.getName(), MethodType.methodType(returnClass, parameterClasses)); @@ -191,16 +191,6 @@ public static MethodHandle searchMethod(final @Nullable Class holderClass, fi return null; } - private static boolean matchModifiers(final int modifier, final @Nullable int[] modifiers) { - if (modifiers == null || modifiers.length == 0) return true; - for (final Integer mod : modifiers) { - if ((mod & modifier) == 0) { - return false; - } - } - return true; - } - /** * Gets a handle for a class method. *