Class ReflectionUtil
java.lang.Object
dk.lockfuglsang.minecraft.reflection.ReflectionUtil
Wrapper methods that allow accesss to reflection for backward compatible code.
- Since:
- 1.8
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
cb()
Returns the real packagename for the org.bukkit.craftbukkit packagedumpMethods(Class aClass)
static <T> T
Uses reflection to execute the named method on the supplied class giving the arguments.static <T> T
Uses reflection to execute the named method on the supplied class giving the arguments.static <T> T
execStatic(Class<?> clazz, String methodName, Object... args)
Uses reflection to execute the named method on the supplied class giving the arguments.static Method
findMethod(Class<?> aClass, Class returnType, Class... argTypes)
findMethods(Class<?> aClass, Class returnType, Class... argTypes)
static Class<?>
getBukkitClass(Object craftObject)
Returns the corresponding Bukkit class, given a CraftBukkit implementation object.static String
Returns the current version of the Bukkit implementationstatic <T> T
Returns the value of a field on the object.static Method
static String
Returns the NMS version.static String
getNMSVersion(Object nmsObject)
Returns the current version of the net.minecraft.server implementationstatic String
getPackageName(Object nmsObject)
Returns the packagename of the given object.static <T> T
newInstance(String className, Class<?>[] argTypes, Object... args)
Instantiates an object.static <T> T
newInstance(String className, Object... args)
Instantiates an object.static String
nms()
Returns the real packagename for the net.minecraft.server.static <T> void
Sets the value of a field on the object.
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
getCraftBukkitVersion
Returns the current version of the Bukkit implementation- Returns:
- the current version of the Bukkit implementation
- Since:
- 1.8
-
getNMSVersion
Returns the current version of the net.minecraft.server implementation- Parameters:
nmsObject
- A native object from nms namespace- Returns:
- the current version of the net.minecraft.server implementation
- Since:
- 1.8
-
getNMSVersion
Returns the NMS version.- Returns:
- the NMS version (i.e. "v1_10").
- Since:
- 1.9
-
nms
Returns the real packagename for the net.minecraft.server.- Returns:
- the real packagename for the net.minecraft.server.
- Since:
- 1.9
-
cb
Returns the real packagename for the org.bukkit.craftbukkit package- Returns:
- the real packagename for the org.bukkit.craftbukkit package
- Since:
- 1.9
-
getPackageName
Returns the packagename of the given object.- Parameters:
nmsObject
- An object- Returns:
- the packagename of the given object.
- Since:
- 1.8
-
getBukkitClass
Returns the corresponding Bukkit class, given a CraftBukkit implementation object.- Parameters:
craftObject
- A CraftBukkit implementation of a Bukkit class.- Returns:
- the corresponding Bukkit class, given a CraftBukkit implementation object.
- Since:
- 1.8
-
execStatic
Uses reflection to execute the named method on the supplied class giving the arguments. Sinks all exceptions, but log an entry and returnsnull
- Parameters:
clazz
- The class on which to invoke the methodmethodName
- The name of the method to invokeargs
- The arguments to supply to the method- Returns:
null
or the return-object from the method.- Since:
- 1.8
-
exec
Uses reflection to execute the named method on the supplied class giving the arguments. Sinks all exceptions, but log an entry and returnsnull
- Parameters:
obj
- The object on which to invoke the methodmethodName
- The name of the method to invokeargTypes
- An array of argument-types (classes).args
- The arguments to supply to the method- Returns:
null
or the return-object from the method.- Since:
- 1.8
-
getMethod
public static Method getMethod(Class<?> aClass, String methodName, Class... argTypes) throws NoSuchMethodException- Throws:
NoSuchMethodException
-
findMethod
public static Method findMethod(Class<?> aClass, Class returnType, Class... argTypes) throws NoSuchMethodException- Throws:
NoSuchMethodException
-
findMethods
public static List<Method> findMethods(Class<?> aClass, Class returnType, Class... argTypes) throws NoSuchMethodException- Throws:
NoSuchMethodException
-
exec
Uses reflection to execute the named method on the supplied class giving the arguments. Sinks all exceptions, but log an entry and returnsnull
- Parameters:
obj
- The object on which to invoke the methodmethodName
- The name of the method to invokeargs
- The arguments to supply to the method- Returns:
null
or the return-object from the method.- Since:
- 1.8
-
getField
Returns the value of a field on the object.- Type Parameters:
T
- The type of field- Parameters:
obj
- The objectfieldName
- The name of the field- Returns:
- the value or
null
- Since:
- 1.9
-
setField
Sets the value of a field on the object.- Type Parameters:
T
- The type of field- Parameters:
obj
- The objectfieldName
- The name of the fieldfield
- The value to set- Since:
- 1.9
-
newInstance
Instantiates an object.- Type Parameters:
T
- Return-type- Parameters:
className
- The name of the classargTypes
- An array of argument-typesargs
- An array of arguments- Returns:
- the object, or
null
. - Since:
- 1.9
-
newInstance
Instantiates an object.- Type Parameters:
T
- Return-type- Parameters:
className
- The name of the classargs
- An array of arguments- Returns:
- the object, or
null
. - Since:
- 1.9
-
dumpMethods
-