public final class Reflection
extends java.lang.Object
Modified Reflection utility from LagMonitor plugin. https://github.com/games647/LagMonitor/blob/master/src/main/java/com/github/games647/lagmonitor/traffic/Reflection.java
Modifier and Type | Class and Description |
---|---|
static interface |
Reflection.FieldAccessor<T>
An interface for retrieving the field content.
|
static interface |
Reflection.MethodInvoker
An interface for invoking a specific method.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Class<?> |
getCraftBukkitClass(java.lang.String name)
Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.
|
static <T> Reflection.FieldAccessor<T> |
getField(java.lang.Class<?> target,
java.lang.String name,
java.lang.Class<T> fieldType)
Retrieve a field accessor for a specific field type and name.
|
static Reflection.MethodInvoker |
getMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... params)
Search for the first publicly and privately defined method of the given name and parameter count.
|
static java.lang.Class<?> |
getMinecraftClass(java.lang.String name)
Retrieve a class in the net.minecraft.server.VERSION.* package.
|
static Reflection.MethodInvoker |
getTypedMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?> returnType,
java.lang.Class<?>... params)
Search for the first publicly and privately defined method of the given name and parameter count.
|
public static <T> Reflection.FieldAccessor<T> getField(java.lang.Class<?> target, java.lang.String name, java.lang.Class<T> fieldType)
T
- Type of the field.target
- - the target type.name
- - the name of the field, or NULL to ignore.fieldType
- - a compatible field type.public static Reflection.MethodInvoker getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... params)
clazz
- - a class to start with.methodName
- - the method name, or NULL to skip.params
- - the expected parameters.java.lang.IllegalStateException
- If we cannot find this method.public static Reflection.MethodInvoker getTypedMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?> returnType, java.lang.Class<?>... params)
clazz
- - a class to start with.methodName
- - the method name, or NULL to skip.returnType
- - the expected return type, or NULL to ignore.params
- - the expected parameters.java.lang.IllegalStateException
- If we cannot find this method.public static java.lang.Class<?> getMinecraftClass(java.lang.String name)
name
- - the name of the class, excluding the package.java.lang.IllegalArgumentException
- If the class doesn't exist.public static java.lang.Class<?> getCraftBukkitClass(java.lang.String name)
name
- - the name of the class, excluding the package.java.lang.IllegalArgumentException
- If the class doesn't exist.