public class NBTCompound extends Object implements ReadWriteNBT
NBTContainer
Modifier | Constructor and Description |
---|---|
protected |
NBTCompound(NBTCompound owner,
String name) |
protected |
NBTCompound(NBTCompound owner,
String name,
boolean readOnly) |
Modifier and Type | Method and Description |
---|---|
NBTCompound |
addCompound(String name)
Creates a subCompound, or returns it if already provided
|
String |
asNBTString()
Deprecated.
Just use toString()
|
void |
clearNBT()
Remove all keys from this compound
|
boolean |
equals(Object obj)
Does a deep compare to check if everything is the same
|
<T> T |
get(String key,
NBTHandler<T> handler)
Get the object at the specified key via the handler.
|
Boolean |
getBoolean(String key)
Getter
|
Byte |
getByte(String key)
Getter
|
byte[] |
getByteArray(String key)
Getter
|
Object |
getCompound() |
NBTCompound |
getCompound(String name) |
NBTCompoundList |
getCompoundList(String name) |
Double |
getDouble(String key)
Getter
|
NBTList<Double> |
getDoubleList(String name) |
<E extends Enum<E>> |
getEnum(String key,
Class<E> type)
Get an Enum value that has been set via setEnum or setString(key,
value.name()).
|
Float |
getFloat(String key)
Getter
|
NBTList<Float> |
getFloatList(String name) |
int[] |
getIntArray(String key)
Getter
|
NBTList<int[]> |
getIntArrayList(String name) |
Integer |
getInteger(String key)
Getter
|
NBTList<Integer> |
getIntegerList(String name) |
org.bukkit.inventory.ItemStack |
getItemStack(String key)
Get an ItemStack that was saved at the given key
|
org.bukkit.inventory.ItemStack[] |
getItemStackArray(String key)
Get an
ItemStack array that was saved at the given key, or null if no
stored data was found |
Set<String> |
getKeys() |
NBTType |
getListType(String name)
Returns the type of the list, null if not a list
|
Long |
getLong(String key)
Getter
|
long[] |
getLongArray(String key)
Getter
Requires at least 1.16
|
NBTList<Long> |
getLongList(String name) |
String |
getName() |
<T> T |
getObject(String key,
Class<T> type)
Deprecated.
|
NBTCompound |
getOrCreateCompound(String name)
The same as addCompound, just with a name that better reflects what it does
|
<T> T |
getOrDefault(String key,
T defaultValue)
Returns the stored value if exists, or provided value otherwise.
|
<T> T |
getOrNull(String key,
Class<?> type)
Returns the stored value if exists, or null.
|
NBTCompound |
getParent() |
protected Lock |
getReadLock() |
protected Object |
getResolvedObject() |
Short |
getShort(String key)
Getter
|
String |
getString(String key)
Getter
|
NBTList<String> |
getStringList(String name) |
NBTType |
getType(String name) |
UUID |
getUUID(String key)
Getter
|
NBTList<UUID> |
getUUIDList(String name) |
protected Lock |
getWriteLock() |
int |
hashCode() |
Boolean |
hasKey(String key)
Deprecated.
Use
hasTag(String) instead |
boolean |
hasTag(String key)
Checks whether the provided key exists
|
protected boolean |
isClosed() |
protected boolean |
isReadOnly() |
void |
mergeCompound(NBTCompound comp)
Merges all data from comp into this compound.
|
void |
mergeCompound(ReadableNBT comp)
Merges all data from comp into this compound.
|
void |
removeKey(String key) |
ReadWriteNBT |
resolveCompound(String key)
Returns the resolved Compound if exists, or null.
|
ReadWriteNBT |
resolveOrCreateCompound(String key)
Returns the resolved and creates compounds as required.
|
<T> T |
resolveOrDefault(String key,
T defaultValue)
Returns the resolved value if exists, or provided value otherwise.
|
<T> T |
resolveOrNull(String key,
Class<?> type)
Returns the resolved value if exists, or null.
|
protected void |
saveCompound() |
protected void |
set(String key,
Object val) |
<T> void |
set(String key,
T value,
NBTHandler<T> handler)
Set an Object to a key via the provided handler.
|
void |
setBoolean(String key,
Boolean value)
Setter
|
void |
setByte(String key,
Byte value)
Setter
|
void |
setByteArray(String key,
byte[] value)
Setter
|
protected void |
setClosed() |
protected void |
setCompound(Object compound) |
void |
setDouble(String key,
Double value)
Setter
|
<E extends Enum<?>> |
setEnum(String key,
E value)
Set a key to the given Enum value.
|
void |
setFloat(String key,
Float value)
Setter
|
void |
setIntArray(String key,
int[] value)
Setter
|
void |
setInteger(String key,
Integer value)
Setter
|
void |
setItemStack(String key,
org.bukkit.inventory.ItemStack item)
Save an ItemStack as a compound under a given key
|
void |
setItemStackArray(String key,
org.bukkit.inventory.ItemStack[] items)
Save an ItemStack Array as a compound under a given key
|
void |
setLong(String key,
Long value)
Setter
|
void |
setLongArray(String key,
long[] value)
Setter
Requires at least 1.16
|
void |
setObject(String key,
Object value)
Deprecated.
|
protected void |
setResolvedObject(Object object) |
void |
setShort(String key,
Short value)
Setter
|
void |
setString(String key,
String value)
Setter
|
void |
setUUID(String key,
UUID value)
Setter
|
String |
toString() |
String |
toString(String key)
Deprecated.
Just use toString()
|
void |
writeCompound(OutputStream stream)
Write the content of this Compound into the provided stream.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
hasTag
protected NBTCompound(NBTCompound owner, String name)
protected NBTCompound(NBTCompound owner, String name, boolean readOnly)
protected Lock getReadLock()
protected Lock getWriteLock()
protected void saveCompound()
protected void setResolvedObject(Object object)
protected void setClosed()
protected boolean isClosed()
protected boolean isReadOnly()
protected Object getResolvedObject()
public String getName()
public Object getCompound()
protected void setCompound(Object compound)
public NBTCompound getParent()
public void mergeCompound(NBTCompound comp)
comp
- public void mergeCompound(ReadableNBT comp)
ReadWriteNBT
mergeCompound
in interface ReadWriteNBT
public void setString(String key, String value)
setString
in interface ReadWriteNBT
key
- value
- public String getString(String key)
getString
in interface ReadableNBT
key
- public void setInteger(String key, Integer value)
setInteger
in interface ReadWriteNBT
key
- value
- public Integer getInteger(String key)
getInteger
in interface ReadableNBT
key
- public void setDouble(String key, Double value)
setDouble
in interface ReadWriteNBT
key
- value
- public Double getDouble(String key)
getDouble
in interface ReadableNBT
key
- public void setByte(String key, Byte value)
setByte
in interface ReadWriteNBT
key
- value
- public Byte getByte(String key)
getByte
in interface ReadableNBT
key
- public void setShort(String key, Short value)
setShort
in interface ReadWriteNBT
key
- value
- public Short getShort(String key)
getShort
in interface ReadableNBT
key
- public void setLong(String key, Long value)
setLong
in interface ReadWriteNBT
key
- value
- public Long getLong(String key)
getLong
in interface ReadableNBT
key
- public void setFloat(String key, Float value)
setFloat
in interface ReadWriteNBT
key
- value
- public Float getFloat(String key)
getFloat
in interface ReadableNBT
key
- public void setByteArray(String key, byte[] value)
setByteArray
in interface ReadWriteNBT
key
- value
- public byte[] getByteArray(String key)
getByteArray
in interface ReadableNBT
key
- public void setIntArray(String key, int[] value)
setIntArray
in interface ReadWriteNBT
key
- value
- public int[] getIntArray(String key)
getIntArray
in interface ReadableNBT
key
- public void setLongArray(String key, long[] value)
setLongArray
in interface ReadWriteNBT
key
- value
- public long[] getLongArray(String key)
getLongArray
in interface ReadableNBT
key
- public void setBoolean(String key, Boolean value)
setBoolean
in interface ReadWriteNBT
key
- value
- public Boolean getBoolean(String key)
getBoolean
in interface ReadableNBT
key
- @Deprecated public void setObject(String key, Object value)
Serializable
Object. Deprecated to clarify that
it's probably missused. Preferably do the serializing yourself.key
- value
- @Deprecated public <T> T getObject(String key, Class<T> type)
key
- type
- Class of the Objectpublic void setItemStack(String key, org.bukkit.inventory.ItemStack item)
setItemStack
in interface ReadWriteNBT
key
- item
- public org.bukkit.inventory.ItemStack getItemStack(String key)
getItemStack
in interface ReadableNBT
key
- public void setItemStackArray(String key, org.bukkit.inventory.ItemStack[] items)
setItemStackArray
in interface ReadWriteNBT
key
- items
- public org.bukkit.inventory.ItemStack[] getItemStackArray(String key)
ItemStack
array that was saved at the given key, or null if no
stored data was foundgetItemStackArray
in interface ReadableNBT
key
- keyItemStack
array, or null if stored data wasn't
foundpublic void setUUID(String key, UUID value)
setUUID
in interface ReadWriteNBT
key
- value
- public UUID getUUID(String key)
getUUID
in interface ReadableNBT
key
- @Deprecated public Boolean hasKey(String key)
hasTag(String)
insteadkey
- String keypublic boolean hasTag(String key)
hasTag
in interface ReadableNBT
key
- String keypublic void removeKey(String key)
removeKey
in interface ReadWriteNBT
key
- Deletes the given Keypublic Set<String> getKeys()
getKeys
in interface ReadableNBT
public NBTCompound addCompound(String name)
name
- Key to usepublic NBTCompound getCompound(String name)
getCompound
in interface ReadableNBT
getCompound
in interface ReadWriteNBT
name
- public NBTCompound getOrCreateCompound(String name)
getOrCreateCompound
in interface ReadWriteNBT
name
- public NBTList<String> getStringList(String name)
getStringList
in interface ReadableNBT
getStringList
in interface ReadWriteNBT
name
- public NBTList<Integer> getIntegerList(String name)
getIntegerList
in interface ReadableNBT
getIntegerList
in interface ReadWriteNBT
name
- public NBTList<int[]> getIntArrayList(String name)
getIntArrayList
in interface ReadableNBT
getIntArrayList
in interface ReadWriteNBT
name
- public NBTList<UUID> getUUIDList(String name)
getUUIDList
in interface ReadableNBT
getUUIDList
in interface ReadWriteNBT
name
- public NBTList<Float> getFloatList(String name)
getFloatList
in interface ReadableNBT
getFloatList
in interface ReadWriteNBT
name
- public NBTList<Double> getDoubleList(String name)
getDoubleList
in interface ReadableNBT
getDoubleList
in interface ReadWriteNBT
name
- public NBTList<Long> getLongList(String name)
getLongList
in interface ReadableNBT
getLongList
in interface ReadWriteNBT
name
- public NBTType getListType(String name)
getListType
in interface ReadableNBT
name
- public NBTCompoundList getCompoundList(String name)
getCompoundList
in interface ReadableNBT
getCompoundList
in interface ReadWriteNBT
name
- public <T> T getOrDefault(String key, T defaultValue)
Supported types:
Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]
,
String
, UUID
, and Enum
getOrDefault
in interface ReadableNBT
T
- value typekey
- keydefaultValue
- default non-null valuepublic <T> T getOrNull(String key, Class<?> type)
Supported types:
Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]
,
String
, UUID
, and Enum
getOrNull
in interface ReadableNBT
T
- value typekey
- keytype
- data typepublic <T> T resolveOrNull(String key, Class<?> type)
ReadableNBT
Supported types:
Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]
,
String
, UUID
, and Enum
resolveOrNull
in interface ReadableNBT
T
- value typekey
- Path key, seperated by '.'. For example: "foo.bar.baz". Dots can
be escaped with a backslash.type
- data typepublic <T> T resolveOrDefault(String key, T defaultValue)
ReadableNBT
Supported types:
Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]
,
String
, UUID
, and Enum
resolveOrDefault
in interface ReadableNBT
T
- value typekey
- Path key, seperated by '.'. For example: "foo.bar.baz".
Dots can be escaped with a backslash.defaultValue
- default non-null valuepublic ReadWriteNBT resolveCompound(String key)
ReadableNBT
resolveCompound
in interface ReadableNBT
resolveCompound
in interface ReadWriteNBT
key
- Path key, seperated by '.'. For example: "foo.bar.baz". Dots can
be escaped with a backslash.public ReadWriteNBT resolveOrCreateCompound(String key)
ReadWriteNBT
resolveOrCreateCompound
in interface ReadWriteNBT
key
- Path key, seperated by '.'. For example: "foo.bar.baz". Dots can
be escaped with a backslash.public <E extends Enum<?>> void setEnum(String key, E value)
setEnum
in interface ReadWriteNBT
E
- key
- value
- public <E extends Enum<E>> E getEnum(String key, Class<E> type)
getEnum
in interface ReadableNBT
E
- key
- type
- public NBTType getType(String name)
getType
in interface ReadableNBT
name
- public void writeCompound(OutputStream stream)
ReadableNBT
writeCompound
in interface ReadableNBT
public <T> T get(String key, NBTHandler<T> handler)
ReadableNBT
get
in interface ReadableNBT
public <T> void set(String key, T value, NBTHandler<T> handler)
ReadWriteNBT
set
in interface ReadWriteNBT
public String toString()
toString
in interface ReadableNBT
toString
in class Object
@Deprecated public String toString(String key)
key
- public void clearNBT()
clearNBT
in interface ReadWriteNBT
@Deprecated public String asNBTString()
String
representation of the NBT in Mojang JSON. This is
different from normal JSON!Copyright © 2015–2024 tr7zw. All rights reserved.