Skip to content

Commit

Permalink
Compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kangarko committed Nov 11, 2024
1 parent 66ff64b commit 72979f2
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/org/mineacademy/fo/ReflectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ public static Method getMethod(final Class<?> clazz, final String methodName) {
return method;
}

for (final Method method : clazz.getDeclaredMethods())
if (method.getName().equals(methodName) && method.getParameterCount() == 0) {
method.setAccessible(true);

return method;
}

return null;
}

Expand Down Expand Up @@ -417,13 +424,16 @@ public static Method getDeclaredMethod(Class<?> clazz, final String methodName,
* Invoke a static method
*
* @param <T>
* @param cl
* @param clazz
* @param methodName
* @param params
* @return
*/
public static <T> T invokeStatic(final Class<?> cl, final String methodName, final Object... params) {
return invokeStatic(getMethod(cl, methodName), params);
public static <T> T invokeStatic(@NonNull final Class<?> clazz, final String methodName, final Object... params) {
final Method method = getMethod(clazz, methodName);
Valid.checkNotNull(method, "Method " + clazz + "." + methodName + "(" + Common.join(params) + ") not found!");

return invokeStatic(method, params);
}

/**
Expand Down Expand Up @@ -847,6 +857,7 @@ else if (rawName.equals("HOT_FLOOR"))
* @param name
* @return the enum, or null if not exists
*/
@SuppressWarnings("rawtypes")
public static <E> E lookupEnumSilent(final Class<E> enumClass, final String name) {
try {

Expand Down Expand Up @@ -885,7 +896,9 @@ public static <E> E lookupEnumSilent(final Class<E> enumClass, final String name
if (hasKey)
return (E) method.invoke(null, name);

// Resort to enum name
if (enumClass.isEnum())
return (E) Enum.valueOf((Class<Enum>) enumClass, name);

return ReflectionUtil.invokeStatic(enumClass, "valueOf", name);

} catch (final IllegalArgumentException ex) {
Expand Down

0 comments on commit 72979f2

Please sign in to comment.