Package me.bimmr.bimmcore.reflection
Class Reflection
- java.lang.Object
-
- me.bimmr.bimmcore.reflection.Reflection
-
public class Reflection extends java.lang.Object
A Utilities class to handle reflection
-
-
Constructor Summary
Constructors Constructor Description Reflection()
-
Method Summary
Modifier and Type Method Description static java.lang.Object
get(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object object)
Assumes field isn't privatestatic java.lang.Object
get(java.lang.reflect.Field field, java.lang.Object object)
Get object.static java.lang.Object
get(java.lang.String fieldName, java.lang.Object object)
Assumes field isn't privatestatic java.lang.Class<?>
getClass(java.lang.String name)
Get a classstatic java.lang.reflect.Constructor
getConstructor(java.lang.Class<?> c, java.lang.Class<?>... types)
Get Constructor from classstatic java.lang.Class<?>
getCraftClass(java.lang.String name)
Get a bukkit class (org.bukkit.craftbukkit)static java.lang.reflect.Field
getField(java.lang.Class<?> c, java.lang.String fieldName)
Gets field.static java.lang.Object
getHandle(java.lang.Object object)
Get the handle of the passed objectstatic java.lang.reflect.Method
getMethod(java.lang.Class<?> c, java.lang.String methodName)
Get a method from the classstatic java.lang.reflect.Method
getMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
Get a method from a class with specific parameter typesstatic java.lang.Class<?>
getNMSClass(java.lang.String name)
Get a craft class (net.minecraft.server)static org.bukkit.entity.Player[]
getOnlinePlayers()
Get online players player [ ].static java.lang.String
getVersion()
Get the server's versionstatic java.lang.Object
invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
Invoke a methodstatic java.lang.Object
invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object)
Invoke a method on an objectstatic java.lang.Object
invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
Invoke method object.static java.lang.Object
invokeMethod(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object... args)
Invoke method object.static java.lang.Object
invokeMethod(java.lang.String methodName, java.lang.Object object)
Invoke a method on an objectstatic java.lang.Object
newInstance(java.lang.reflect.Constructor constructor, java.lang.Object... args)
New instance object.static void
setField(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object obj, java.lang.Object value)
Set a Fieldstatic void
setField(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object value)
Set a Field
-
-
-
Method Detail
-
getVersion
public static java.lang.String getVersion()
Get the server's version- Returns:
- version
-
getNMSClass
public static java.lang.Class<?> getNMSClass(java.lang.String name)
Get a craft class (net.minecraft.server)- Parameters:
name
- the name- Returns:
- nms class
-
getCraftClass
public static java.lang.Class<?> getCraftClass(java.lang.String name)
Get a bukkit class (org.bukkit.craftbukkit)- Parameters:
name
- the name- Returns:
- craft class
-
getClass
public static java.lang.Class<?> getClass(java.lang.String name)
Get a class- Parameters:
name
- the name- Returns:
- craft class
-
getHandle
public static java.lang.Object getHandle(java.lang.Object object)
Get the handle of the passed object- Parameters:
object
- the object- Returns:
- handle
-
getConstructor
public static java.lang.reflect.Constructor getConstructor(java.lang.Class<?> c, java.lang.Class<?>... types)
Get Constructor from class- Parameters:
c
- the ctypes
- the types- Returns:
- constructor
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class<?> c, java.lang.String methodName)
Get a method from the class- Parameters:
c
- the cmethodName
- the method name- Returns:
- method
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
Get a method from a class with specific parameter types- Parameters:
c
- the cmethodName
- the method nameparameterTypes
- the parameter types- Returns:
- method
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
Invoke a method- Parameters:
c
- the cmethodName
- the method nameparameterTypes
- the parameter typesparameter
- the parameter- Returns:
- the object
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object)
Invoke a method on an object- Parameters:
c
- the cmethodName
- the method nameobject
- the object- Returns:
- the object
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object object)
Invoke a method on an object- Parameters:
methodName
- the method nameobject
- the object- Returns:
- the object
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
Invoke method object.- Parameters:
c
- The ClassmethodName
- The MethodNameobject
- The ObjectparameterTypes
- The ParameterTypessparameter
- The Parameters- Returns:
- The Object from the Invoked Method
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object... args)
Invoke method object.- Parameters:
method
- The Methodobject
- The Objectargs
- The Args- Returns:
- The object from the Invoked Method
-
newInstance
public static java.lang.Object newInstance(java.lang.reflect.Constructor constructor, java.lang.Object... args)
New instance object.- Parameters:
constructor
- The Constructorargs
- The args- Returns:
- Get a new instance from a constructor
-
setField
public static void setField(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object obj, java.lang.Object value)
Set a Field- Parameters:
c
- The ClassfieldName
- The FieldNameobj
- The Objectvalue
- The Value
-
setField
public static void setField(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object value)
Set a Field- Parameters:
field
- The fieldobj
- The Objectvalue
- The Value
-
getField
public static java.lang.reflect.Field getField(java.lang.Class<?> c, java.lang.String fieldName)
Gets field.- Parameters:
c
- The ClassfieldName
- The FieldName- Returns:
- Get the field from the class
-
get
public static java.lang.Object get(java.lang.reflect.Field field, java.lang.Object object)
Get object.- Parameters:
field
- The fieldobject
- The Object- Returns:
- Get the Object from the Field
-
get
public static java.lang.Object get(java.lang.String fieldName, java.lang.Object object)
Assumes field isn't private- Parameters:
fieldName
- The fieldobject
- The Object- Returns:
- Get the Object from the Field
-
get
public static java.lang.Object get(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object object)
Assumes field isn't private- Parameters:
c
- The ClassfieldName
- The fieldobject
- The Object- Returns:
- Get the Object from the Field
-
getOnlinePlayers
public static org.bukkit.entity.Player[] getOnlinePlayers()
Get online players player [ ].- Returns:
- Get Array of online players regardless of Mc Version
-
-