Package de.themoep.utils
Class ReflectionUtils
java.lang.Object
de.themoep.utils.ReflectionUtils
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionClass
<?> Get a registered obfuscated classGet a registered obfuscated fieldstatic Method
Get a methodGet a registered obfuscated methodInvoke a method registered with the ReflectionUtilsClass
<?> registerClass
(String path) Register a new class with the ReflectionUtils, the part after the last dot will be used as the name!Class
<?> registerClass
(String path, String className) Register a new class with the ReflectionUtilsregisterField
(String className, String name, Class<?> fieldType) Register a new field with the ReflectionUtilsregisterMethod
(String className, String methodName, Class<?> returnType, Class<?>... parameters) Register a new method with the ReflectionUtilsregisterObfuscatedField
(String className, String fieldName, Class<?> fieldType) Register a new field that is obfuscated and the name may change so we use the first we find with that typeregisterObfuscatedField
(String className, String fieldName, String obf, Class<?> fieldType) Register a new field that is obfuscated and the name may changeregisterObfuscatedMethod
(String className, String methodName, Class<?> returnType, Class<?>... parameters) Register a new method which may be obfuscated so we use the first we find that matches the argumentsregisterObfuscatedMethod
(String className, String methodName, String obf, Class<?> returnType, Class<?>... parameters) Register a new method which may be obfuscated
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils(org.bukkit.plugin.java.JavaPlugin plugin)
-
-
Method Details
-
getClass
Get a registered obfuscated class- Parameters:
className
- The name of the class- Returns:
- The class by that name
- Throws:
ClassNotFoundException
- Thrown when the class was not registered
-
getMethod
Get a registered obfuscated method- Parameters:
name
- The name of the method- Returns:
- The method by that name
- Throws:
NoSuchMethodException
- Thrown when the method was not registered
-
getField
Get a registered obfuscated field- Parameters:
name
- The name of the field- Returns:
- The field by that name
- Throws:
NoSuchFieldException
- Thrown when the field was not registered
-
invoke
public Object invoke(String name, Object object, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException Invoke a method registered with the ReflectionUtils- Parameters:
name
- The name of the method registered. Eg. Class.methodobject
- The object to invoke the method onargs
- Optional arguments- Returns:
- The return of the method, null if it is void
- Throws:
NoSuchMethodException
- Thrown when the field isn't foundInvocationTargetException
- Thrown when you aren't allowed to invoke that methodIllegalAccessException
- Thrown when you aren't allowed to access that method
-
registerClass
Register a new class with the ReflectionUtils, the part after the last dot will be used as the name!- Parameters:
path
- The path to the class including the name- Returns:
- The registered class
- Throws:
ClassNotFoundException
- Thrown when the class isn't found
-
registerClass
Register a new class with the ReflectionUtils- Parameters:
path
- The path to the class including the nameclassName
- The name of the class you want to use in in the getClass() method- Returns:
- The registered class
- Throws:
ClassNotFoundException
- Thrown when the class isn't found
-
registerMethod
public Method registerMethod(String className, String methodName, Class<?> returnType, Class<?>... parameters) throws ClassNotFoundException, NoSuchMethodException, ReflectionUtils.WrongTypeException Register a new method with the ReflectionUtils- Parameters:
className
- The name of the class as registered beforemethodName
- The name of the methodreturnType
- The return type of this methodparameters
- Optional parameters of the method- Returns:
- The registered method
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchMethodException
- Thrown when the field isn't foundReflectionUtils.WrongTypeException
- Thrown when the method doesn't return that type
-
registerObfuscatedMethod
public Method registerObfuscatedMethod(String className, String methodName, Class<?> returnType, Class<?>... parameters) throws ClassNotFoundException, NoSuchMethodException Register a new method which may be obfuscated so we use the first we find that matches the arguments- Parameters:
className
- The name of the class as registered beforemethodName
- The name of the methodreturnType
- The return type of this methodparameters
- Optional parameters of the method- Returns:
- The registered method
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchMethodException
- Thrown when the method isn't found
-
registerObfuscatedMethod
public Method registerObfuscatedMethod(String className, String methodName, String obf, Class<?> returnType, Class<?>... parameters) throws ClassNotFoundException, NoSuchMethodException Register a new method which may be obfuscated- Parameters:
className
- The name of the class as registered beforemethodName
- The name of the methodobf
- If we have multiple methods that match, which one should we use?returnType
- The return type of this methodparameters
- Optional parameters of the method- Returns:
- The registered method
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchMethodException
- Thrown when the method isn't found
-
registerField
public Field registerField(String className, String name, Class<?> fieldType) throws ClassNotFoundException, NoSuchFieldException, ReflectionUtils.WrongTypeException Register a new field with the ReflectionUtils- Parameters:
className
- The name of the class as registered beforename
- The name of the fieldfieldType
- The type of the field- Returns:
- The registered field
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchFieldException
- Thrown when the field isn't foundReflectionUtils.WrongTypeException
- Thrown when the field doesn't have that type
-
registerObfuscatedField
public Field registerObfuscatedField(String className, String fieldName, Class<?> fieldType) throws ClassNotFoundException, NoSuchFieldException Register a new field that is obfuscated and the name may change so we use the first we find with that type- Parameters:
className
- The name of the class as registered beforefieldName
- The name of the fieldfieldType
- The type of the field- Returns:
- The registered field
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchFieldException
- Thrown when the field wasn't found
-
registerObfuscatedField
public Field registerObfuscatedField(String className, String fieldName, String obf, Class<?> fieldType) throws ClassNotFoundException, NoSuchFieldException Register a new field that is obfuscated and the name may change- Parameters:
className
- The name of the class as registered beforefieldName
- The name of the fieldobf
- If we have multiple fields that match, which one should we use?fieldType
- The type of the field- Returns:
- The registered field
- Throws:
ClassNotFoundException
- Thrown when the class isn't foundNoSuchFieldException
- Thrown when the field wasn't found
-
getMethod
public static Method getMethod(Class<?> c, String name, Class<?> returnType, Class<?>... args) throws NoSuchMethodException, ReflectionUtils.WrongTypeException Get a method- Parameters:
c
- The classname
- The method namereturnType
- The return typeargs
- The method arguments- Returns:
- The method
- Throws:
NoSuchMethodException
- Thrown when there is no such methodReflectionUtils.WrongTypeException
- Thrown when the method doesn't return that type
-