Package valorless.rarespawns.utils
Class Reflex
java.lang.Object
valorless.rarespawns.utils.Reflex
Lightweight reflection helpers for accessing private members and invoking methods.
Notes:
- getMethod and setFieldValue operate on declared members of the given class only (no superclass traversal).
- Members are set accessible=true before use.
- Errors are logged via stack traces; null is returned or the call is no-op on failure.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MethodReturns a declared Method from the specified class and makes it accessible.static voidinvokeMethod(Method method, Object instance, Object... args) Invokes a Method on the given instance with the provided arguments.static voidsetFieldValue(Object instance, String fieldName, Object value) Sets the value of a declared field on an instance and makes it accessible.
-
Constructor Details
-
Reflex
public Reflex()
-
-
Method Details
-
getMethod
Returns a declared Method from the specified class and makes it accessible.This does not search superclasses; use clazz.getSuperclass() manually if needed.
- Parameters:
clazz- the class declaring the methodname- the method nameparameterTypes- the formal parameter types in declaration order- Returns:
- the accessible Method, or null if not found
-
invokeMethod
Invokes a Method on the given instance with the provided arguments.For static methods, pass null as the instance. Any return value is ignored. Exceptions are caught and printed.
- Parameters:
method- the method to invoke (should already be accessible)instance- the target object instance, or null for static methodsargs- the arguments to pass to the invocation
-
setFieldValue
Sets the value of a declared field on an instance and makes it accessible.This does not search superclasses; only the instance's concrete class is used. Exceptions are caught and printed.
- Parameters:
instance- the object whose field should be updatedfieldName- the declared field name on the instance's classvalue- the value to assign to the field
-