Package net.glowstone.util.nbt
Class CompoundTag
- All Implemented Interfaces:
DynamicallyTypedMap<String>
,DynamicallyTypedMapWithDoubles<String>
,DynamicallyTypedMapWithFloats<String>
public class CompoundTag
extends Tag<Map<String,Tag>>
implements DynamicallyTypedMapWithDoubles<String>
The
TAG_Compound
tag.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(@NonNls String key) Check if the compound contains the given key.boolean
getBoolean
(@NonNls String key) Retrieves an entry as aboolean
.boolean
getBoolean
(@NonNls String key, boolean defaultValue) Returns the boolean value of abyte
subtag if present, or a default otherwise.byte
Returns the value of abyte
subtag.byte[]
getByteArray
(@NonNls String key) Returns the value of abyte[]
subtag.getCompound
(@NonNls String key) Returns the value of a compound subtag.getCompoundList
(@NonNls String key) Returns the value of a list subtag with CompoundTag elements.double
Returns the value of adouble
subtag.float
Returns the value of afloat
subtag.int
Returns the value of anint
subtag.int[]
getIntArray
(@NonNls String key) Returns the value of anint[]
subtag.<V> List<V>
Returns the value of aList
subtag.long
Returns the value of along
subtag.long[]
getLongArray
(@NonNls String key) Returns the value of anlong[]
subtag.Returns the value of a numeric subtag.short
Returns the value of ashort
subtag.Returns the value of aString
subtag.getValue()
The value.boolean
Test whether the subtag with the given key is ofbyte
type.boolean
isByteArray
(@NonNls String key) Test whether the subtag with the given key is ofbyte[]
type.boolean
isCompound
(@NonNls String key) Test whether the subtag with the given key is ofCompoundTag
type.boolean
isCompoundList
(@NonNls String key) Test whether the subtag with the given key is ofList
type with elements of typeCompoundTag
.boolean
Test whether the subtag with the given key is ofdouble
type.boolean
isEmpty()
boolean
Test whether the subtag with the given key is offloat
type.boolean
Test whether the subtag with the given key is ofint
type.boolean
isIntArray
(@NonNls String key) Test whether the subtag with the given key is ofint[]
type.boolean
Test whether the subtag with the given key is ofList
type.boolean
Test whether the subtag with the given key is oflong
type.boolean
isLongArray
(@NonNls String key) Test whether the subtag with the given key is oflong[]
type.boolean
Test whether the subtag with the given key is of a numeric type.boolean
Test whether the subtag with the given key is ofshort
type.boolean
Test whether the subtag with the given key is ofString
type.boolean
iterateCompoundList
(@NonNls String key, Consumer<? super CompoundTag> consumer) Applies the given function to each compound tag in a compound-list subtag, if that subtag exists.boolean
matches
(CompoundTag other) Checks to see if this tag is a strict, deep submap of the given CompoundTag.void
mergeInto
(CompoundTag other, boolean overwrite) Merges the contents of this compound into the supplied compound.void
void
void
putByteArray
(@NonNls String key, byte... value) void
putCompound
(@NonNls String key, CompoundTag tag) void
putCompoundList
(@NonNls String key, List<CompoundTag> list) Adds or replaces a list subtag with a list of compound tags.void
void
putDoubleList
(@NonNls String key, List<Double> list) Adds or replaces a list subtag with a list of doubles.void
void
putFloatList
(@NonNls String key, List<Float> list) Adds or replaces a list subtag with a list of floats.void
void
putIntArray
(@NonNls String key, int... value) <V> void
putList
(@NonNls String key, TagType type, List<V> value, Function<? super V, ? extends Tag> tagCreator) Adds or replaces a list subtag, converting the list entries to tags.void
void
putLongArray
(@NonNls String key, long... value) void
putLongList
(@NonNls String key, List<Long> list) Adds or replaces a list subtag with a list of longs.void
void
void
putStringList
(@NonNls String key, List<String> list) Adds or replaces a list subtag with a list of strings.void
putUniqueId
(@NonNls String key, UUID uuid) boolean
readBoolean
(@NonNls String key, Consumer<? super Boolean> consumer) Applies the given function to a byte subtag if it is present, converting it to boolean first.boolean
readBooleanNegated
(@NonNls String key, Consumer<? super Boolean> consumer) Applies the given function to a byte subtag if it is present, converting it to boolean and negating it first.boolean
Applies the given function to a byte subtag if it is present.boolean
readByteArray
(@NonNls String key, Consumer<? super byte[]> consumer) Applies the given function to a byte array subtag if it is present.boolean
readCompound
(@NonNls String key, Consumer<? super CompoundTag> consumer) Applies the given function to a compound subtag if it is present.boolean
readCompoundList
(@NonNls String key, Consumer<? super List<CompoundTag>> consumer) Applies the given function to a list subtag if it is present and its contents are compound tags.boolean
readDouble
(@NonNls String key, DoubleConsumer consumer) Applies the given function to a double subtag if it is present.boolean
readDoubleList
(@NonNls String key, Consumer<? super List<Double>> consumer) Applies the given function to a list subtag if it is present and its contents are double tags.boolean
readFloat
(@NonNls String key, FloatConsumer consumer) Applies the given function to a float subtag if it is present.boolean
readFloatList
(@NonNls String key, Consumer<? super List<Float>> consumer) Applies the given function to a list subtag if it is present and its contents are float tags.boolean
readInt
(@NonNls String key, IntConsumer consumer) Applies the given function to an integer subtag if it is present.boolean
readIntArray
(@NonNls String key, Consumer<? super int[]> consumer) Applies the given function to an integer array subtag if it is present.boolean
Applies the given function to a compound subtag if it is present, first converting it to an item usingNbtSerialization.readItem(CompoundTag)
.<T> boolean
Applies the given function to a list subtag if it is present, converting it to a list of values first.boolean
readLong
(@NonNls String key, LongConsumer consumer) Applies the given function to a long subtag if it is present.boolean
readLongArray
(@NonNls String key, Consumer<? super long[]> consumer) boolean
readShort
(@NonNls String key, ShortConsumer consumer) Applies the given function to an integer subtag if it is present.boolean
readString
(@NonNls String key, Consumer<? super String> consumer) Applies the given function to a string subtag if it is present.boolean
readStringList
(@NonNls String key, Consumer<? super List<String>> consumer) Applies the given function to a list subtag if it is present and its contents are string tags.boolean
readUniqueId
(@NonNls String keyMost, @NonNls String keyLeast, Consumer<? super UUID> consumer) Deprecated.boolean
readUniqueId
(@NonNls String key, Consumer<? super UUID> consumer) void
Optional<org.bukkit.block.data.BlockData>
tryGetBlockData
(@NonNls String key) tryGetCompound
(@NonNls String key) Returns the value of a compound subtag, if it exists.Returns the value of an int subtag if it is present.tryGetLong
(@NonNls String key) Returns the value of a long subtag if it is present.Optional<org.bukkit.Material>
tryGetMaterial
(@NonNls String key) Reads a material from a string ID or numeric ID, depending on the tag type.tryGetString
(@NonNls String key) Returns the value of a string subtag if it is present.tryGetUniqueId
(@NonNls String key) tryGetUniqueId
(@NonNls String keyMost, @NonNls String keyLeast) Deprecated.usetryGetUniqueId(String)
for modern int-array UUID representation.protected void
valueToString
(StringBuilder builder)
-
Constructor Details
-
CompoundTag
public CompoundTag()Creates a new, empty CompoundTag. -
CompoundTag
-
-
Method Details
-
valueToString
- Overrides:
valueToString
in classTag<Map<String,
Tag>>
-
isEmpty
public boolean isEmpty() -
containsKey
Check if the compound contains the given key.- Parameters:
key
- The key.- Returns:
- True if the key is in the map.
-
remove
-
matches
Checks to see if this tag is a strict, deep submap of the given CompoundTag.- Parameters:
other
- The CompoundTag that should contain our values.
-
mergeInto
Merges the contents of this compound into the supplied compound.- Parameters:
other
- the other compound to merge into.overwrite
- whether keys already set in the other compound should be overwritten.
-
getNumber
Returns the value of a numeric subtag.- Parameters:
key
- the key to look up- Returns:
- the numeric tag value
-
getByte
Returns the value of abyte
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getShort
Returns the value of ashort
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getInt
Returns the value of anint
subtag.- Specified by:
getInt
in interfaceDynamicallyTypedMap<String>
- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getBoolean
Description copied from interface:DynamicallyTypedMap
Retrieves an entry as aboolean
.- Specified by:
getBoolean
in interfaceDynamicallyTypedMap<String>
- Parameters:
key
- the key to look up- Returns:
- the value as a boolean
-
getBoolean
Returns the boolean value of abyte
subtag if present, or a default otherwise.- Parameters:
key
- the key to look updefaultValue
- the value to return if the subtag is missing- Returns:
- the tag value as a boolean, or defaultValue if it's not a byte
-
getLong
Returns the value of along
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getFloat
Returns the value of afloat
subtag.- Specified by:
getFloat
in interfaceDynamicallyTypedMapWithFloats<String>
- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getDouble
Returns the value of adouble
subtag.- Specified by:
getDouble
in interfaceDynamicallyTypedMapWithDoubles<String>
- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getByteArray
Returns the value of abyte[]
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getString
Returns the value of aString
subtag.- Specified by:
getString
in interfaceDynamicallyTypedMap<String>
- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getIntArray
Returns the value of anint[]
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getLongArray
Returns the value of anlong[]
subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
getList
Returns the value of aList
subtag.- Type Parameters:
V
- the list element type- Parameters:
key
- the key to look uptype
- the list element tag type- Returns:
- the tag value
-
getCompound
Returns the value of a compound subtag.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
tryGetCompound
Returns the value of a compound subtag, if it exists. Multiple strings can be passed in to retrieve a sub-subtag (e.g.tryGetCompound("foo", "bar")
returns a compound subtag called "bar" of a compound subtag called "foo", or null if either of those tags doesn't exist or isn't compound.- Parameters:
key
- the key to look up- Returns:
- the tag value, or an empty optional if the tag doesn't exist or isn't compound
-
readCompound
Applies the given function to a compound subtag if it is present. Multiple strings can be passed in to operate on a sub-subtag, as withtryGetCompound(String)
.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readFloat
Applies the given function to a float subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readDouble
Applies the given function to a double subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readInt
Applies the given function to an integer subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readByteArray
Applies the given function to a byte array subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readIntArray
Applies the given function to an integer array subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readLongArray
-
readLong
Applies the given function to a long subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
tryGetLong
Returns the value of a long subtag if it is present.- Parameters:
key
- the key to look up- Returns:
- an Optional with the value of that tag if it's present and is a long; an empty Optional otherwise
-
readShort
Applies the given function to an integer subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readItem
public boolean readItem(@NonNls @NonNls String key, Consumer<? super org.bukkit.inventory.ItemStack> consumer) Applies the given function to a compound subtag if it is present, first converting it to an item usingNbtSerialization.readItem(CompoundTag)
.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readBoolean
Applies the given function to a byte subtag if it is present, converting it to boolean first.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readByte
Applies the given function to a byte subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readBooleanNegated
Applies the given function to a byte subtag if it is present, converting it to boolean and negating it first.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readList
public <T> boolean readList(@NonNls @NonNls String key, TagType type, Consumer<? super List<T>> consumer) Applies the given function to a list subtag if it is present, converting it to a list of values first.- Type Parameters:
T
- the type to convert the list entries to- Parameters:
key
- the key to look uptype
- the type that the list entries must beconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readCompoundList
public boolean readCompoundList(@NonNls @NonNls String key, Consumer<? super List<CompoundTag>> consumer) Applies the given function to a list subtag if it is present and its contents are compound tags. Processes the list as a single object; to process each tag separately, instead useiterateCompoundList(String, Consumer)
.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
iterateCompoundList
public boolean iterateCompoundList(@NonNls @NonNls String key, Consumer<? super CompoundTag> consumer) Applies the given function to each compound tag in a compound-list subtag, if that subtag exists.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was iterated over (even if it was empty); false otherwise
-
readStringList
Applies the given function to a list subtag if it is present and its contents are string tags.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readFloatList
Applies the given function to a list subtag if it is present and its contents are float tags.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readDoubleList
Applies the given function to a list subtag if it is present and its contents are double tags.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
readString
Applies the given function to a string subtag if it is present.- Parameters:
key
- the key to look upconsumer
- the function to apply- Returns:
- true if the tag exists and was passed to the consumer; false otherwise
-
tryGetMaterial
Reads a material from a string ID or numeric ID, depending on the tag type. Returns null if the tag isn't present, its type is neither string nor any integral type, or its value isn't a valid material ID.- Parameters:
key
- the key to look up- Returns:
- the Material denoted by that key, if present and readable; an empty Optional otherwise
-
tryGetBlockData
-
tryGetString
Returns the value of a string subtag if it is present.- Parameters:
key
- the key to look up- Returns:
- an Optional with the value of that tag if it's present and is a string; an empty optional otherwise
-
tryGetInt
Returns the value of an int subtag if it is present.- Parameters:
key
- the key to look up- Returns:
- an Optional with the value of that tag if it's present and is an int; an empty optional otherwise
-
readUniqueId
@Deprecated public boolean readUniqueId(@NonNls @NonNls String keyMost, @NonNls @NonNls String keyLeast, Consumer<? super UUID> consumer) Deprecated.usereadUniqueId(String, Consumer)
for modern int-array UUID representation.Applies the given function to a UUID extracted from the given pair of long subtags, if they both exist.
Uses Most/Least representation.- Parameters:
keyMost
- the key to look up the high word of the UUIDkeyLeast
- the key to look up the low word of the UUIDconsumer
- the function to apply- Returns:
- true if the tags exist and were passed to the consumer; false otherwise
-
readUniqueId
-
tryGetUniqueId
@Deprecated public Optional<UUID> tryGetUniqueId(@NonNls @NonNls String keyMost, @NonNls @NonNls String keyLeast) Deprecated.usetryGetUniqueId(String)
for modern int-array UUID representation.Returns a UUID extracted from the given pair of long subtags, if they both exist.- Parameters:
keyMost
- the key to look up the high word of the UUIDkeyLeast
- the key to look up the low word of the UUID- Returns:
- the UUID, or an empty Optional if either tag is missing or not long type
-
tryGetUniqueId
-
getCompoundList
Returns the value of a list subtag with CompoundTag elements.- Parameters:
key
- the key to look up- Returns:
- the tag value
-
isNumeric
Test whether the subtag with the given key is of a numeric type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is numeric; false otherwise
-
isByte
Test whether the subtag with the given key is ofbyte
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
byte
; false otherwise
-
isShort
Test whether the subtag with the given key is ofshort
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
short
; false otherwise
-
isInt
Test whether the subtag with the given key is ofint
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is an
int
; false otherwise
-
isLong
Test whether the subtag with the given key is oflong
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
long
; false otherwise
-
isFloat
Test whether the subtag with the given key is offloat
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
float
; false otherwise
-
isDouble
Test whether the subtag with the given key is ofdouble
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
double
; false otherwise
-
isByteArray
Test whether the subtag with the given key is ofbyte[]
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
byte[]
; false otherwise
-
isString
Test whether the subtag with the given key is ofString
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
String
; false otherwise
-
isIntArray
Test whether the subtag with the given key is ofint[]
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is an
int[]
; false otherwise
-
isLongArray
Test whether the subtag with the given key is oflong[]
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is an
long[]
; false otherwise
-
isList
Test whether the subtag with the given key is ofList
type. -
isCompound
Test whether the subtag with the given key is ofCompoundTag
type.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
CompoundTag
; false otherwise
-
isCompoundList
Test whether the subtag with the given key is ofList
type with elements of typeCompoundTag
.- Parameters:
key
- the key to look up- Returns:
- true if the subtag exists and is a
List
with elements of typeCompoundTag
; false otherwise
-
putBool
-
putByte
-
putShort
-
putInt
-
putLong
-
putFloat
-
putDouble
-
putByteArray
-
putString
-
putIntArray
-
putLongArray
-
putList
public <V> void putList(@NonNls @NonNls String key, TagType type, List<V> value, Function<? super V, ? extends Tag> tagCreator) Adds or replaces a list subtag, converting the list entries to tags.- Type Parameters:
V
- the list elements' Java type- Parameters:
key
- the key to write totype
- the list elements' tag typevalue
- the list contents, as objects to convert to tagstagCreator
- a function that will convert each V to an element tag
-
putCompound
-
putCompoundList
Adds or replaces a list subtag with a list of compound tags.- Parameters:
key
- the key to write tolist
- the list contents as compound tags
-
putStringList
Adds or replaces a list subtag with a list of strings.- Parameters:
key
- the key to write tolist
- the list contents as strings, to convert to string tags
-
putFloatList
Adds or replaces a list subtag with a list of floats.- Parameters:
key
- the key to write tolist
- the list contents as floats, to convert to float tags
-
putDoubleList
Adds or replaces a list subtag with a list of doubles.- Parameters:
key
- the key to write tolist
- the list contents as doubles, to convert to double tags
-
putLongList
Adds or replaces a list subtag with a list of longs.- Parameters:
key
- the key to write tolist
- the list contents as longs, to convert to long tags
-
putUniqueId
-
getValue
The value.
-
readUniqueId(String, Consumer)
for modern int-array UUID representation.