public class NbtFactory extends 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(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(Object handle)
Deprecated.
|
static <T> NbtWrapper<T> |
fromNMS(Object handle,
String name)
Initialize a NBT wrapper with a name.
|
static NbtCompound |
fromNMSCompound(Object handle)
Retrieve the NBT compound from a given NMS handle.
|
static NbtBase<Byte> |
of(String name,
byte value)
Constructs a NBT tag of type byte.
|
static NbtBase<byte[]> |
of(String name,
byte[] value)
Constructs a NBT tag of type byte array.
|
static NbtBase<Double> |
of(String name,
double value)
Constructs a NBT tag of type double.
|
static NbtBase<Float> |
of(String name,
float value)
Constructs a NBT tag of type float.
|
static NbtBase<Integer> |
of(String name,
int value)
Constructs a NBT tag of type int.
|
static NbtBase<int[]> |
of(String name,
int[] value)
Constructs a NBT tag of type int array.
|
static NbtBase<Long> |
of(String name,
long value)
Constructs a NBT tag of type long.
|
static NbtBase<Short> |
of(String name,
short value)
Constructs a NBT tag of type short.
|
static NbtBase<String> |
of(String name,
String value)
Constructs a NBT tag of type string.
|
static NbtCompound |
ofCompound(String name)
Construct a new NBT compound wrapper.
|
static NbtCompound |
ofCompound(String name,
Collection<? extends NbtBase<?>> list)
Construct a new NBT compound initialized with a given list of NBT values.
|
static <T> NbtList<T> |
ofList(String name,
Collection<? extends T> elements)
Construct a NBT list of out a list of values.
|
static <T> NbtList<T> |
ofList(String name,
T... elements)
Construct a NBT list of out an array of values.
|
static <T> NbtWrapper<T> |
ofWrapper(Class<?> type,
String name,
T value)
Create a new NBT wrapper from a given type.
|
static <T> NbtWrapper<T> |
ofWrapper(NbtType type,
String name)
Create a new NBT wrapper from a given type.
|
static <T> NbtWrapper<T> |
ofWrapper(NbtType type,
String name,
T value)
Create a new NBT wrapper from a given type.
|
static NbtCompound |
readBlockState(org.bukkit.block.Block block)
Retrieve the NBT tile entity that represents the given block.
|
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,
String file)
Save a NBT compound to a new compressed file, overwriting any existing files in the process.
|
static void |
writeBlockState(org.bukkit.block.Block target,
NbtCompound blockState)
Write to the NBT tile entity in the given block.
|
public static NbtCompound asCompound(NbtBase<?> tag)
tag - - the NBT tag to cast.UnsupportedOperationException - If this is not a compound.public static NbtList<?> asList(NbtBase<?> tag)
tag - - the NBT tag to cast.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.
T - Typebase - - 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#getCraftItemStack(ItemStack) if not.
stack - - the item stack, cannot be air.compound - - the new NBT compound, or NULL to remove it.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#getCraftItemStack(ItemStack) if not.
stack - - the item stack.public static NbtCompound fromFile(String file) throws IOException
file - - the source file.IOException - Unable to load file.public static void toFile(NbtCompound compound, String file) throws IOException
compound - - the compound to save.file - - the destination file.IOException - Unable to save compound.public static NbtCompound readBlockState(org.bukkit.block.Block block)
block - - the block.public static void writeBlockState(org.bukkit.block.Block target,
NbtCompound blockState)
target - - the target block.blockState - - the new tile entity.IllegalArgumentException - If the block doesn't contain a tile entity.@Deprecated public static <T> NbtWrapper<T> fromNMS(Object handle)
Use fromNMS(Object, String) instead.
T - Typehandle - - the underlying net.minecraft.server object to wrap.public static <T> NbtWrapper<T> fromNMS(Object handle, String name)
T - Typename - - the name of the tag, or NULL if not valid.handle - - the underlying net.minecraft.server object to wrap.public static NbtCompound fromNMSCompound(@Nonnull Object handle)
handle - - the underlying net.minecraft.server object to wrap.public static NbtBase<String> of(String name, String value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Byte> of(String name, byte value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Short> of(String name, short value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Integer> of(String name, int value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Long> of(String name, long value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Float> of(String name, float value)
name - - name of the tag.value - - value of the tag.public static NbtBase<Double> of(String name, double value)
name - - name of the tag.value - - value of the tag.public static NbtBase<byte[]> of(String name, byte[] value)
name - - name of the tag.value - - value of the tag.public static NbtBase<int[]> of(String name, int[] value)
name - - name of the tag.value - - value of the tag.public static NbtCompound ofCompound(String name, Collection<? extends NbtBase<?>> list)
name - - the name of the compound wrapper.list - - the list of elements to add.public static NbtCompound ofCompound(String name)
name - - the name of the compound wrapper.@SafeVarargs public static <T> NbtList<T> ofList(String name, T... elements)
T - Typename - - name of this list.elements - - elements to add.public static <T> NbtList<T> ofList(String name, Collection<? extends T> elements)
T - Typename - - name of this list.elements - - elements to add.public static <T> NbtWrapper<T> ofWrapper(NbtType type, String name)
T - Typetype - - 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, String name, T value)
T - Typetype - - 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(Class<?> type, String name, T value)
T - Typetype - - 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.IllegalArgumentException - If the given class type is not valid NBT.Copyright © 2012–2017 Comphenix and dmulloy2. Licensed under the GNU GPL v2.