public class NBTLib extends Object
The "main" class and base of NBTLib.
If you're just using NBT Tags, see the NBT Class
.
If you need to access other methods or fields of Minecraft or Craftbukkit, this is for you.
Note: When accessing private or protected fields of methods, you must specify the class declaring the field or method! Subclasses will not work!!
Modifier and Type | Field and Description |
---|---|
static Logger |
_log
Just the console.
|
static String |
_version
Just the NBTLib version.
|
Constructor and Description |
---|
NBTLib() |
Modifier and Type | Method and Description |
---|---|
static boolean |
enabled()
Returns
true if NBTLib is enabled and false otherwise. |
static Object |
fetchCraftbukkitField(String className,
Object object,
String name)
Fetches the value of a field of a Craftbukkit class.
|
static Object |
fetchDynamicCraftbukkitField(String className,
Object object,
Object type)
Fetches the value of a field of a Craftbukkit class without knowing the name of the field.
|
static Object |
fetchDynamicField(String className,
Object object,
Object type)
Tries to identify a field of class by the fields type and returns the value of the first found field.
|
static Object |
fetchDynamicMinecraftField(String className,
Object object,
Object type)
Fetches the value of a field of a Minecraft class without knowing the name of the field.
|
static Object |
fetchField(String className,
Object object,
String name)
Fetches the value of a field of a class.
|
static Object |
fetchMinecraftField(String className,
Object object,
String name)
Fetches the value of a field of a Minecraft class.
|
static Constructor |
getConstructor(Class clazz,
Class... paramTypes)
Returns the constructor of a class.
|
static Class |
getCraftbukkitClass(String className)
Returns a
Class from the Craftbukkit package. |
static String |
getCraftbukkitPackage()
Returns the Craftbukkit package name with a trailing dot.
|
static Field |
getField(Class clazz,
Class type)
Tries to identify a field of class by the fields type.
|
static Field |
getField(Class clazz,
String name)
Returns a field of a class.
|
static Method |
getMethod(Class clazz,
Class returnType,
Class... params)
Returns a method of a class.
|
static Method |
getMethod(Class clazz,
String name,
Class... params)
Returns a method of a class.
|
static Class |
getMinecraftClass(String className)
Returns a
Class from the Minecraft package. |
static String |
getMinecraftPackage()
Returns the Minecraft package name with a trailing dot.
|
static String |
getMinecraftVersion()
Returns the Minecraft version.
|
static String |
getPackageVersion()
Returns the Minecraft package version.
|
static Object |
instantiate(String className,
Object[] paramTypes,
Object... params)
Returns a new instance of
className . |
static Object |
instantiateCraftbukkit(String className,
Object[] paramTypes,
Object... params)
Returns a new instance of a Craftbukkit class.
|
static Object |
instantiateMinecraft(String className,
Object[] paramTypes,
Object... params)
Returns a new instance of a Minecraft class.
|
static Object |
invoke(String className,
Object object,
String name,
Object[] paramTypes,
Object... params)
Invokes a method of a class.
|
static Object |
invokeCraftbukkit(String className,
Object object,
String name,
Object[] paramTypes,
Object... params)
Invokes a method of a Craftbukkit class.
|
static Object |
invokeCraftbukkitDynamic(String className,
Object object,
Object returnType,
Object[] paramTypes,
Object... params)
Tries to invoke a method of a Craftbukkit class without knowing the methods name.
|
static Object |
invokeDynamic(String className,
Object object,
Object returnType,
Object[] paramTypes,
Object... params)
Tries to identify a method of a class by its return and parameter types.
|
static Object |
invokeMinecraft(String className,
Object object,
String name,
Object[] paramTypes,
Object... params)
Invokes a method of a Minecraft class.
|
static Object |
invokeMinecraftDynamic(String className,
Object object,
Object returnType,
Object[] paramTypes,
Object... params)
Tries to invoke a method of a Minecraft class without knowing the methods name.
|
static Class[] |
parseClass(Object... array)
|
static Class |
parseClass(Object o)
|
static void |
putCraftbukkitField(String className,
Object object,
String name,
Object value)
Puts a value into a field of a Craftbukkit class.
|
static void |
putDynamicCraftbukkitField(String className,
Object object,
Object type,
Object value)
Puts a value into a field of a Craftbukkit class without knowing the name of the field.
|
static void |
putDynamicField(String className,
Object object,
Object type,
Object value)
Tries to identify a field of class by the fields type and puts the value into the first found field.
|
static void |
putDynamicMinecraftField(String className,
Object object,
Object type,
Object value)
Puts a value into a field of a Minecraft class without knowing the name of the field.
|
static void |
putField(String className,
Object object,
String name,
Object value)
Puts a value into a field of a class.
|
static void |
putMinecraftField(String className,
Object object,
String name,
Object value)
Puts a value into a field of a Minecraft class.
|
public static final String _version
public static final Logger _log
public static boolean enabled()
true
if NBTLib is enabled and false
otherwise.true
if NBTLib is enabled, false
otherwise.public static Class getMinecraftClass(String className) throws ClassNotFoundException, NBTLibDisabledException
Class
from the Minecraft package.className
- The name of the class.ClassNotFoundException
- If the class could not be found.NBTLibDisabledException
- If NBTLib
has been disabled.public static Class getCraftbukkitClass(String className) throws ClassNotFoundException, NBTLibDisabledException
Class
from the Craftbukkit package.className
- The name of the class.ClassNotFoundException
- If the class could not be found.NBTLibDisabledException
- If NBTLib
has been disabled.public static String getPackageVersion()
Returns the Minecraft package version.
Example: v1_7_R1
public static String getMinecraftVersion()
Returns the Minecraft version.
This simply calls Bukkit.getVersion()
.
public static String getMinecraftPackage() throws NBTLibDisabledException
net.minecraft.server.v1_7_R1.
NBTLibDisabledException
- If NBTLib
has been disabled.public static String getCraftbukkitPackage() throws NBTLibDisabledException
org.bukkit.craftbukkit.v1_7_R1.
NBTLibDisabledException
- If NBTLib
has been disabled.public static Object fetchDynamicMinecraftField(String className, Object object, Object type) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Fetches the value of a field of a Minecraft class without knowing the name of the field.
className
- The name of the class.object
- The instance of which the fields value should be fetched. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static Object fetchMinecraftField(String className, Object object, String name) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Fetches the value of a field of a Minecraft class.
className
- The name of the class.object
- The instance of which the fields value should be fetched. Use null
for static fields.name
- The name of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static Object fetchDynamicCraftbukkitField(String className, Object object, Object type) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Fetches the value of a field of a Craftbukkit class without knowing the name of the field.
className
- The name of the class (with leading subpackages!).object
- The instance of which the fields value should be fetched. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static Object fetchCraftbukkitField(String className, Object object, String name) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Fetches the value of a field of a Craftbukkit class.
className
- The name of the class (with leading subpackages!).object
- The instance of which the fields value should be fetched. Use null
for static fields.name
- The name of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static Object fetchDynamicField(String className, Object object, Object type) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException
Tries to identify a field of class by the fields type and returns the value of the first found field.
className
- The full name of the class.object
- The instance of which the fields value should be fetched. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.public static Object fetchField(String className, Object object, String name) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException
Fetches the value of a field of a class.
className
- The full name of the class.object
- The instance of which the fields value should be fetched. Use null
for static fields.name
- The name of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.public static void putDynamicMinecraftField(String className, Object object, Object type, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Puts a value into a field of a Minecraft class without knowing the name of the field.
className
- The name of the class.object
- The instance of which the fields value should be changed. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static void putMinecraftField(String className, Object object, String name, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Puts a value into a field of a Minecraft class.
className
- The name of the class.object
- The instance of which the fields value should be changed. Use null
for static fields.name
- The name of the field.value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static void putDynamicCraftbukkitField(String className, Object object, Object type, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Puts a value into a field of a Craftbukkit class without knowing the name of the field.
className
- The name of the class (with leading subpackages!).object
- The instance of which the fields value should be changed. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static void putCraftbukkitField(String className, Object object, String name, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NBTLibDisabledException
Puts a value into a field of a Craftbukkit class.
className
- The name of the class (with leading subpackages!).object
- The instance of which the fields value should be changed. Use null
for static fields.name
- The name of the field.value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.NBTLibDisabledException
- If NBTLib
has been disabled.public static void putDynamicField(String className, Object object, Object type, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException
Tries to identify a field of class by the fields type and puts the value into the first found field.
className
- The full name of the class.object
- The instance of which the fields value should be changed. Use null
for static fields.type
- The type of the field, must be an instance of either Class
or String
(the class or its name).value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.public static void putField(String className, Object object, String name, Object value) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException
Puts a value into a field of a class.
className
- The full name of the class.object
- The instance of which the fields value should be changed. Use null
for static fields.name
- The name of the field.value
- The new value of the field.ClassNotFoundException
- If the class className
cannot be found.IllegalAccessException
- If the field cannot be accessed.NoSuchFieldException
- If the field doesn't exist.public static Field getField(Class clazz, Class type) throws NoSuchFieldException
Tries to identify a field of class by the fields type. The first matching field will be returned.
clazz
- The class.type
- The type of the field.NoSuchFieldException
- If the field doesn't exist.public static Field getField(Class clazz, String name) throws NoSuchFieldException
Returns a field of a class.
clazz
- The class.name
- The name of the field.NoSuchFieldException
- If the field doesn't exist.public static Object instantiateMinecraft(String className, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Returns a new instance of a Minecraft class.
className
- The name of the Minecraft class.paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the constructor.className
.ClassNotFoundException
IllegalAccessException
InstantiationException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object instantiateCraftbukkit(String className, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Returns a new instance of a Craftbukkit class.
className
- The name of the Craftbukkit class (with leading subpackages!).paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the constructor.className
.ClassNotFoundException
IllegalAccessException
InstantiationException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object instantiate(String className, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
Returns a new instance of className
.
className
- The full name of the class.paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the constructor.className
.ClassNotFoundException
IllegalAccessException
InstantiationException
InvocationTargetException
NoSuchMethodException
public static Constructor getConstructor(Class clazz, Class... paramTypes) throws NoSuchMethodException
Returns the constructor of a class.
clazz
- The class.paramTypes
- The classes of the parameters.NoSuchMethodException
public static Object invokeMinecraftDynamic(String className, Object object, Object returnType, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Tries to invoke a method of a Minecraft class without knowing the methods name.
Tries to identify a method of a Minecraft class by its return and parameter types. The first one found will be invoked.
Example: (Given: byte[] array;
)
NBTLib.invokeMinecraftDynamic("NBTCompressedStreamTools", null, NBTLib.getMinecraftPackage() + "NBTTagCompound", new Object[]{byte[].class}, new Object[]{array});
className
- The name of the Minecraft class.object
- The instance on which the method should be invoked. Use null
for static methods.returnType
- The return type, must be an instance of either Class
or String
(the class or its name).paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object invokeMinecraft(String className, Object object, String name, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Invokes a method of a Minecraft class.
className
- The name of the Minecraft class.object
- The instance on which the method should be invoked. Use null
for static methods.name
- The name of the called method.paramTypes
- An array of Classes
and/or Strings
representing the parameter types (classes and/or their names).params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object invokeCraftbukkitDynamic(String className, Object object, Object returnType, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Tries to invoke a method of a Craftbukkit class without knowing the methods name.
Tries to identify a method of a Craftbukkit class by its return and parameter types. The first one found will be invoked.
Example: (Given: Object item;
but actually instance of net.minecraft.server.v_1_4_6.ItemStack
)
NBTLib.invokeCraftbukkit("inventory.CraftItemStack", null, "asBukkitCopy", new Object[]{NBTLib.getMinecraftPackage() + "ItemStack"}, new Object[]{item});
className
- The name of the Craftbukkit class (with leading subpackages!).object
- The instance on which the method should be invoked. Use null
for static methods.returnType
- The return type, must be an instance of either Class
or String
(the class or its name).paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object invokeCraftbukkit(String className, Object object, String name, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NBTLibDisabledException
Invokes a method of a Craftbukkit class.
className
- The name of the Craftbukkit class.object
- The instance on which the method should be invoked. Use null
for static methods.name
- The name of the called method.paramTypes
- An array of Classes
and/or Strings
representing the parameter types (classes and/or their names).params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
NBTLibDisabledException
public static Object invokeDynamic(String className, Object object, Object returnType, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
Tries to identify a method of a class by its return and parameter types. The first one found will be invoked.
className
- The full name of the class.object
- The instance on which the method should be invoked. Use null
for static methods.returnType
- The return type, must be an instance of either Class
or String
(the class or its name).paramTypes
- An array of Classes
and/or Strings
representing the parameter types.params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
public static Object invoke(String className, Object object, String name, Object[] paramTypes, Object... params) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
Invokes a method of a class.
className
- The full name of the class.object
- The instance on which the method should be invoked. Use null
for static methods.name
- The name of the called method.paramTypes
- An array of Classes
and/or Strings
representing the parameter types (classes and/or their names).params
- The arguments to pass to the method.ClassNotFoundException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
public static Method getMethod(Class clazz, Class returnType, Class... params) throws NoSuchMethodException
Returns a method of a class. The method is identified by its return type and its parameter types. The first matching method will be returned.
clazz
- The class containing the method.returnType
- The class of the returned object.params
- The classes of the parameters.NoSuchMethodException
public static Method getMethod(Class clazz, String name, Class... params) throws NoSuchMethodException
Returns a method of a class.
clazz
- The class containing the method.name
- The name of the method.params
- The classes of the parameters.NoSuchMethodException
public static Class[] parseClass(Object... array) throws ClassNotFoundException
array
- An array of Classes
and/or Strings
.ClassNotFoundException
public static Class parseClass(Object o) throws ClassNotFoundException
o
- A String
or Class
.ClassNotFoundException
Copyright © 2013. All Rights Reserved.