public class NbtFactory
extends java.lang.Object
Constructor and Description |
---|
NbtFactory() |
Modifier and Type | Method and Description |
---|---|
static NbtCompound |
asCompound(NbtBase<?> tag)
Attempt to cast this NBT tag as a compund.
|
static NbtList<?> |
asList(NbtBase<?> tag)
Attempt to cast this NBT tag as a list.
|
static <T> NbtWrapper<T> |
fromBase(NbtBase<T> base)
Get a NBT wrapper from a NBT base.
|
static NbtCompound |
fromFile(java.lang.String file)
Load a NBT compound from a GZIP compressed file.
|
static NbtWrapper<?> |
fromItemTag(org.bukkit.inventory.ItemStack stack)
Construct a wrapper for an NBT tag stored (in memory) in an item stack.
|
static <T> NbtWrapper<T> |
fromNMS(java.lang.Object handle)
Deprecated.
|
static <T> NbtWrapper<T> |
fromNMS(java.lang.Object handle,
java.lang.String name)
Initialize a NBT wrapper with a name.
|
static NbtCompound |
fromNMSCompound(java.lang.Object handle)
Retrieve the NBT compound from a given NMS handle.
|
static NbtBase<java.lang.Byte> |
of(java.lang.String name,
byte value)
Constructs a NBT tag of type byte.
|
static NbtBase<byte[]> |
of(java.lang.String name,
byte[] value)
Constructs a NBT tag of type byte array.
|
static NbtBase<java.lang.Double> |
of(java.lang.String name,
double value)
Constructs a NBT tag of type double.
|
static NbtBase<java.lang.Float> |
of(java.lang.String name,
float value)
Constructs a NBT tag of type float.
|
static NbtBase<java.lang.Integer> |
of(java.lang.String name,
int value)
Constructs a NBT tag of type int.
|
static NbtBase<int[]> |
of(java.lang.String name,
int[] value)
Constructs a NBT tag of type int array.
|
static NbtBase<java.lang.Long> |
of(java.lang.String name,
long value)
Constructs a NBT tag of type long.
|
static NbtBase<java.lang.Short> |
of(java.lang.String name,
short value)
Constructs a NBT tag of type short.
|
static NbtBase<java.lang.String> |
of(java.lang.String name,
java.lang.String value)
Constructs a NBT tag of type string.
|
static NbtCompound |
ofCompound(java.lang.String name)
Construct a new NBT compound wrapper.
|
static NbtCompound |
ofCompound(java.lang.String name,
java.util.Collection<? extends NbtBase<?>> list)
Construct a new NBT compound initialized with a given list of NBT values.
|
static <T> NbtList<T> |
ofList(java.lang.String name,
java.util.Collection<? extends T> elements)
Construct a NBT list of out a list of values.
|
static <T> NbtList<T> |
ofList(java.lang.String name,
T... elements)
Construct a NBT list of out an array of values.
|
static <T> NbtWrapper<T> |
ofWrapper(java.lang.Class<?> type,
java.lang.String name,
T value)
Create a new NBT wrapper from a given type.
|
static <T> NbtWrapper<T> |
ofWrapper(NbtType type,
java.lang.String name)
Create a new NBT wrapper from a given type.
|
static <T> NbtWrapper<T> |
ofWrapper(NbtType type,
java.lang.String name,
T value)
Create a new NBT wrapper from a given type.
|
static void |
setItemTag(org.bukkit.inventory.ItemStack stack,
NbtCompound compound)
Set the NBT compound tag of a given item stack.
|
static void |
toFile(NbtCompound compound,
java.lang.String file)
Save a NBT compound to a new compressed file, overwriting any existing files in the process.
|
public static NbtCompound asCompound(NbtBase<?> tag)
tag
- - the NBT tag to cast.java.lang.UnsupportedOperationException
- If this is not a compound.public static NbtList<?> asList(NbtBase<?> tag)
tag
- - the NBT tag to cast.java.lang.UnsupportedOperationException
- If this is not a list.public static <T> NbtWrapper<T> fromBase(NbtBase<T> base)
This may clone the content if the NbtBase is not a NbtWrapper.
base
- - the base class.public static void setItemTag(org.bukkit.inventory.ItemStack stack, NbtCompound compound)
The item stack must be a wrapper for a CraftItemStack. Use
MinecraftReflection.getBukkitItemStack(ItemStack)
if not.
stack
- - the item stack, cannot be air.compound
- - the new NBT compound, or NULL to remove it.java.lang.IllegalArgumentException
- If the stack is not a CraftItemStack, or it represents air.public static NbtWrapper<?> fromItemTag(org.bukkit.inventory.ItemStack stack)
The item stack must be a wrapper for a CraftItemStack. Use
MinecraftReflection.getBukkitItemStack(ItemStack)
if not.
stack
- - the item stack.public static NbtCompound fromFile(java.lang.String file) throws java.io.IOException
file
- - the source file.java.io.IOException
- Unable to load file.public static void toFile(NbtCompound compound, java.lang.String file) throws java.io.IOException
compound
- - the compound to save.file
- - the destination file.java.io.IOException
- Unable to save compound.@Deprecated public static <T> NbtWrapper<T> fromNMS(java.lang.Object handle)
Use fromNMS(Object, String)
instead.
handle
- - the underlying net.minecraft.server object to wrap.public static <T> NbtWrapper<T> fromNMS(java.lang.Object handle, java.lang.String name)
name
- - the name of the tag, or NULL if not valid.handle
- - the underlying net.minecraft.server object to wrap.public static NbtCompound fromNMSCompound(@Nonnull java.lang.Object handle)
handle
- - the underlying net.minecraft.server object to wrap.public static NbtBase<java.lang.String> of(java.lang.String name, java.lang.String value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Byte> of(java.lang.String name, byte value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Short> of(java.lang.String name, short value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Integer> of(java.lang.String name, int value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Long> of(java.lang.String name, long value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Float> of(java.lang.String name, float value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<java.lang.Double> of(java.lang.String name, double value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<byte[]> of(java.lang.String name, byte[] value)
name
- - name of the tag.value
- - value of the tag.public static NbtBase<int[]> of(java.lang.String name, int[] value)
name
- - name of the tag.value
- - value of the tag.public static NbtCompound ofCompound(java.lang.String name, java.util.Collection<? extends NbtBase<?>> list)
name
- - the name of the compound wrapper.list
- - the list of elements to add.public static NbtCompound ofCompound(java.lang.String name)
name
- - the name of the compound wrapper.public static <T> NbtList<T> ofList(java.lang.String name, T... elements)
name
- - name of this list.elements
- - elements to add.public static <T> NbtList<T> ofList(java.lang.String name, java.util.Collection<? extends T> elements)
name
- - name of this list.elements
- - elements to add.public static <T> NbtWrapper<T> ofWrapper(NbtType type, java.lang.String name)
type
- - the NBT type.name
- - the name of the NBT tag.FieldAccessException
- If we're unable to create the underlying tag.public static <T> NbtWrapper<T> ofWrapper(NbtType type, java.lang.String name, T value)
type
- - the NBT type.name
- - the name of the NBT tag.value
- - the value of the new tag.FieldAccessException
- If we're unable to create the underlying tag.public static <T> NbtWrapper<T> ofWrapper(java.lang.Class<?> type, java.lang.String name, T value)
type
- - type of the NBT value.name
- - the name of the NBT tag.value
- - the value of the new tag.FieldAccessException
- If we're unable to create the underlying tag.java.lang.IllegalArgumentException
- If the given class type is not valid NBT.