“findMethod” that is used by Tweens.callMethod cannot find methods that have primitive parameters like int, float, …
→ int.class.isInstance always returns false
So this statement:
if (paramTypes[i].isInstance(args[i])) {
will always return false when the paramTypes[i] is int.class, float.class,…
So its not working with any method that uses primitives. As soon as you change the signature of the called method to the corresponding wrapped type (e.g Integer instead of int) it works fine. But this is ofc not possible in all cases.
This is one of the possible solutions to fix this:
private static final Map<Class<?>, Class<?>> PRIMITIVES_TO_WRAPPERS
= new ImmutableMap.Builder<Class<?>, Class<?>>()
.put(boolean.class, Boolean.class)
.put(byte.class, Byte.class)
.put(char.class, Character.class)
.put(double.class, Double.class)
.put(float.class, Float.class)
.put(int.class, Integer.class)
.put(long.class, Long.class)
.put(short.class, Short.class)
.put(void.class, Void.class)
.build();
private static Method findMethod(Class type, String name, Object... args) {
for (Method m : type.getDeclaredMethods()) {
if (!Objects.equals(m.getName(), name)) {
continue;
}
Class[] paramTypes = m.getParameterTypes();
if (paramTypes.length != args.length) {
continue;
}
int matches = 0;
for (int i = 0; i < args.length; i++) {
if( PRIMITIVES_TO_WRAPPERS.containsKey(paramTypes[i]) ) {
paramTypes[i] = PRIMITIVES_TO_WRAPPERS.get(paramTypes[i]);
}
if (paramTypes[i].isInstance(args[i])) {
matches++;
}
}
if (matches == args.length) {
return m;
}
}
if (type.getSuperclass() != null) {
return findMethod(type.getSuperclass(), name, args);
}
return null;
}