Class TinyProtocolReflection
- java.lang.Object
-
- me.bimmr.bimmcore.reflection.tinyprotocol.TinyProtocolReflection
-
public final class TinyProtocolReflection extends java.lang.ObjectAn utility class that simplifies reflection in Bukkit plugins.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTinyProtocolReflection.ConstructorInvokerAn interface for invoking a specific constructor.static interfaceTinyProtocolReflection.FieldAccessor<T>An interface for retrieving the field content.static interfaceTinyProtocolReflection.MethodInvokerAn interface for invoking a specific method.
-
Method Summary
Modifier and Type Method Description static java.lang.Class<?>getClass(java.lang.String lookupName)Retrieve a class from its full name.static TinyProtocolReflection.ConstructorInvokergetConstructor(java.lang.Class<?> clazz, java.lang.Class<?>... params)Search for the first publically and privately defined constructor of the given name and parameter count.static TinyProtocolReflection.ConstructorInvokergetConstructor(java.lang.String className, java.lang.Class<?>... params)Search for the first publically and privately defined constructor of the given name and parameter count.static java.lang.Class<?>getCraftBukkitClass(java.lang.String name)Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.static <T> TinyProtocolReflection.FieldAccessor<T>getField(java.lang.Class<?> target, java.lang.Class<T> fieldType, int index)Retrieve a field accessor for a specific field type and name.static <T> TinyProtocolReflection.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 <T> TinyProtocolReflection.FieldAccessor<T>getField(java.lang.String className, java.lang.Class<T> fieldType, int index)Retrieve a field accessor for a specific field type and name.static <T> TinyProtocolReflection.FieldAccessor<T>getField(java.lang.String className, java.lang.String name, java.lang.Class<T> fieldType)Retrieve a field accessor for a specific field type and name.static TinyProtocolReflection.MethodInvokergetMethod(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 TinyProtocolReflection.MethodInvokergetMethod(java.lang.String className, 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 TinyProtocolReflection.MethodInvokergetTypedMethod(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.static java.lang.Class<java.lang.Object>getUntypedClass(java.lang.String lookupName)Retrieve a class from its full name, without knowing its type on compile time.
-
-
-
Method Detail
-
getField
public static <T> TinyProtocolReflection.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.- Parameters:
target- - the target type.name- - the name of the field, or NULL to ignore.fieldType- - a compatible field type.- Returns:
- The field accessor.
-
getField
public static <T> TinyProtocolReflection.FieldAccessor<T> getField(java.lang.String className, java.lang.String name, java.lang.Class<T> fieldType)
Retrieve a field accessor for a specific field type and name.- Parameters:
className- - lookup name of the class, seegetClass(String).name- - the name of the field, or NULL to ignore.fieldType- - a compatible field type.- Returns:
- The field accessor.
-
getField
public static <T> TinyProtocolReflection.FieldAccessor<T> getField(java.lang.Class<?> target, java.lang.Class<T> fieldType, int index)
Retrieve a field accessor for a specific field type and name.- Parameters:
target- - the target type.fieldType- - a compatible field type.index- - the number of compatible fields to skip.- Returns:
- The field accessor.
-
getField
public static <T> TinyProtocolReflection.FieldAccessor<T> getField(java.lang.String className, java.lang.Class<T> fieldType, int index)
Retrieve a field accessor for a specific field type and name.- Parameters:
className- - lookup name of the class, seegetClass(String).fieldType- - a compatible field type.index- - the number of compatible fields to skip.- Returns:
- The field accessor.
-
getMethod
public static TinyProtocolReflection.MethodInvoker getMethod(java.lang.String className, java.lang.String methodName, java.lang.Class<?>... params)
Search for the first publicly and privately defined method of the given name and parameter count.- Parameters:
className- - lookup name of the class, seegetClass(String).methodName- - the method name, or NULL to skip.params- - the expected parameters.- Returns:
- An object that invokes this specific method.
- Throws:
java.lang.IllegalStateException- If we cannot find this method.
-
getMethod
public static TinyProtocolReflection.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.- Parameters:
clazz- - a class to start with.methodName- - the method name, or NULL to skip.params- - the expected parameters.- Returns:
- An object that invokes this specific method.
- Throws:
java.lang.IllegalStateException- If we cannot find this method.
-
getTypedMethod
public static TinyProtocolReflection.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.- Parameters:
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.- Returns:
- An object that invokes this specific method.
- Throws:
java.lang.IllegalStateException- If we cannot find this method.
-
getConstructor
public static TinyProtocolReflection.ConstructorInvoker getConstructor(java.lang.String className, java.lang.Class<?>... params)
Search for the first publically and privately defined constructor of the given name and parameter count.- Parameters:
className- - lookup name of the class, seegetClass(String).params- - the expected parameters.- Returns:
- An object that invokes this constructor.
- Throws:
java.lang.IllegalStateException- If we cannot find this method.
-
getConstructor
public static TinyProtocolReflection.ConstructorInvoker getConstructor(java.lang.Class<?> clazz, java.lang.Class<?>... params)
Search for the first publically and privately defined constructor of the given name and parameter count.- Parameters:
clazz- - a class to start with.params- - the expected parameters.- Returns:
- An object that invokes this constructor.
- Throws:
java.lang.IllegalStateException- If we cannot find this method.
-
getUntypedClass
public static java.lang.Class<java.lang.Object> getUntypedClass(java.lang.String lookupName)
Retrieve a class from its full name, without knowing its type on compile time.This is useful when looking up fields by a NMS or OBC type.
- Parameters:
lookupName- - the class name with variables.- Returns:
- The class.
-
getClass
public static java.lang.Class<?> getClass(java.lang.String lookupName)
Retrieve a class from its full name.Strings enclosed with curly brackets - such as {TEXT} - will be replaced according to the following table:
Variable Content {nms} Actual package name of net.minecraft.server.VERSION {obc} Actual pacakge name of org.bukkit.craftbukkit.VERSION {version} The current Minecraft package VERSION, if any. - Parameters:
lookupName- - the class name with variables.- Returns:
- The looked up class.
- Throws:
java.lang.IllegalArgumentException- If a variable or class could not be found.
-
getMinecraftClass
public static java.lang.Class<?> getMinecraftClass(java.lang.String name)
Retrieve a class in the net.minecraft.server.VERSION.* package.- Parameters:
name- - the name of the class, excluding the package.- Throws:
java.lang.IllegalArgumentException- If the class doesn't exist.
-
getCraftBukkitClass
public static java.lang.Class<?> getCraftBukkitClass(java.lang.String name)
Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.- Parameters:
name- - the name of the class, excluding the package.- Throws:
java.lang.IllegalArgumentException- If the class doesn't exist.
-
-