public final class NMSReflection extends Object
null
.Modifier and Type | Method and Description |
---|---|
static Field |
getField(Class<?> clazz,
String name)
Retrieves a
Field instance declared by the specified class with the specified name. |
static Object |
getHandle(Object obj)
Attempts to get the NMS handle of a CraftBukkit object.
|
static Method |
getMethod(Class<?> clazz,
String name,
Class<?>... args)
Retrieves a
Method instance declared by the specified class with the specified name and argument types. |
static Class<?> |
getNMSClass(String className)
Gets a
Class object representing a type contained within the net.minecraft.server versioned package. |
static Class<?> |
getOBCClass(String className)
Gets a
Class object representing a type contained within the org.bukkit.craftbukkit versioned package. |
static String |
getVersion()
Gets the version string from the package name of the CraftBukkit server implementation.
|
public static String getVersion()
public static Class<?> getNMSClass(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 Class<?> getOBCClass(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 Object getHandle(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 Field getField(Class<?> clazz, 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 Method getMethod(Class<?> clazz, String name, 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.Copyright © 2020. All rights reserved.