public final class Reflection
extends java.lang.Object
null
.Modifier and Type | Method and Description |
---|---|
static java.lang.reflect.Field |
getField(java.lang.Class<?> clazz,
java.lang.String name)
Retrieves a
Field instance declared by the specified class with the specified name. |
static java.lang.Object |
getHandle(java.lang.Object obj)
Attempts to get the NMS handle of a CraftBukkit object.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... args)
Retrieves a
Method instance declared by the specified class with the specified name and argument types. |
static java.lang.Class<?> |
getNMSClass(java.lang.String className)
Gets a
Class object representing a type contained within the net.minecraft.server versioned package. |
static java.lang.Class<?> |
getOBCClass(java.lang.String className)
Gets a
Class object representing a type contained within the org.bukkit.craftbukkit versioned package. |
static java.lang.String |
getVersion()
Gets the version string from the package name of the CraftBukkit server implementation.
|
public static java.lang.String getVersion()
public static java.lang.Class<?> getNMSClass(java.lang.String className)
Class
object representing a type contained within the net.minecraft.server
versioned package.
The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).className
- The name of the class, excluding the package, within NMS.null
if it could not be loaded.public static java.lang.Class<?> getOBCClass(java.lang.String className)
Class
object representing a type contained within the org.bukkit.craftbukkit
versioned package.
The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).className
- The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as inventory.CraftItemStack
.null
if it could not be loaded.public static java.lang.Object getHandle(java.lang.Object obj)
The only match currently attempted by this method is a retrieval by using a parameterless getHandle()
method implemented by the runtime type of the specified object.
obj
- The object for which to retrieve an NMS handle.null
if it could not be retrieved using getHandle()
.public static java.lang.reflect.Field getField(java.lang.Class<?> clazz, java.lang.String name)
Field
instance declared by the specified class with the specified name.
Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
returned will be an instance or static field.
A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that no field will be reflectively looked up twice.
If a field is deemed suitable for return, setAccessible
will be invoked with an argument of true
before it is returned.
This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
clazz
- The class which contains the field to retrieve.name
- The declared name of the field in the class.Class.getDeclaredField(String)
public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... args)
Method
instance declared by the specified class with the specified name and argument types.
Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
returned will be an instance or static field.
A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that no method will be reflectively looked up twice.
If a method is deemed suitable for return, setAccessible
will be invoked with an argument of true
before it is returned.
This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
This method does not search superclasses of the specified type for methods with the specified signature.
Callers wishing this behavior should use Class.getDeclaredMethod(String, Class...)
.
clazz
- The class which contains the method to retrieve.name
- The declared name of the method in the class.args
- The formal argument types of the method.