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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(@NonNls String key) Check if the compound contains the given key.booleangetBoolean(@NonNls String key) Retrieves an entry as aboolean.booleangetBoolean(@NonNls String key, boolean defaultValue) Returns the boolean value of abytesubtag if present, or a default otherwise.byteReturns the value of abytesubtag.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.doubleReturns the value of adoublesubtag.floatReturns the value of afloatsubtag.intReturns the value of anintsubtag.int[]getIntArray(@NonNls String key) Returns the value of anint[]subtag.<V> List<V>Returns the value of aListsubtag.longReturns the value of alongsubtag.long[]getLongArray(@NonNls String key) Returns the value of anlong[]subtag.Returns the value of a numeric subtag.shortReturns the value of ashortsubtag.Returns the value of aStringsubtag.getValue()The value.booleanTest whether the subtag with the given key is ofbytetype.booleanisByteArray(@NonNls String key) Test whether the subtag with the given key is ofbyte[]type.booleanisCompound(@NonNls String key) Test whether the subtag with the given key is ofCompoundTagtype.booleanisCompoundList(@NonNls String key) Test whether the subtag with the given key is ofListtype with elements of typeCompoundTag.booleanTest whether the subtag with the given key is ofdoubletype.booleanisEmpty()booleanTest whether the subtag with the given key is offloattype.booleanTest whether the subtag with the given key is ofinttype.booleanisIntArray(@NonNls String key) Test whether the subtag with the given key is ofint[]type.booleanTest whether the subtag with the given key is ofListtype.booleanTest whether the subtag with the given key is oflongtype.booleanisLongArray(@NonNls String key) Test whether the subtag with the given key is oflong[]type.booleanTest whether the subtag with the given key is of a numeric type.booleanTest whether the subtag with the given key is ofshorttype.booleanTest whether the subtag with the given key is ofStringtype.booleaniterateCompoundList(@NonNls String key, Consumer<? super CompoundTag> consumer) Applies the given function to each compound tag in a compound-list subtag, if that subtag exists.booleanmatches(CompoundTag other) Checks to see if this tag is a strict, deep submap of the given CompoundTag.voidmergeInto(CompoundTag other, boolean overwrite) Merges the contents of this compound into the supplied compound.voidvoidvoidputByteArray(@NonNls String key, byte... value) voidputCompound(@NonNls String key, CompoundTag tag) voidputCompoundList(@NonNls String key, List<CompoundTag> list) Adds or replaces a list subtag with a list of compound tags.voidvoidputDoubleList(@NonNls String key, List<Double> list) Adds or replaces a list subtag with a list of doubles.voidvoidputFloatList(@NonNls String key, List<Float> list) Adds or replaces a list subtag with a list of floats.voidvoidputIntArray(@NonNls String key, int... value) <V> voidputList(@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.voidvoidputLongArray(@NonNls String key, long... value) voidputLongList(@NonNls String key, List<Long> list) Adds or replaces a list subtag with a list of longs.voidvoidvoidputStringList(@NonNls String key, List<String> list) Adds or replaces a list subtag with a list of strings.voidputUniqueId(@NonNls String key, UUID uuid) booleanreadBoolean(@NonNls String key, Consumer<? super Boolean> consumer) Applies the given function to a byte subtag if it is present, converting it to boolean first.booleanreadBooleanNegated(@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.booleanApplies the given function to a byte subtag if it is present.booleanreadByteArray(@NonNls String key, Consumer<? super byte[]> consumer) Applies the given function to a byte array subtag if it is present.booleanreadCompound(@NonNls String key, Consumer<? super CompoundTag> consumer) Applies the given function to a compound subtag if it is present.booleanreadCompoundList(@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.booleanreadDouble(@NonNls String key, DoubleConsumer consumer) Applies the given function to a double subtag if it is present.booleanreadDoubleList(@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.booleanreadFloat(@NonNls String key, FloatConsumer consumer) Applies the given function to a float subtag if it is present.booleanreadFloatList(@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.booleanreadInt(@NonNls String key, IntConsumer consumer) Applies the given function to an integer subtag if it is present.booleanreadIntArray(@NonNls String key, Consumer<? super int[]> consumer) Applies the given function to an integer array subtag if it is present.booleanApplies the given function to a compound subtag if it is present, first converting it to an item usingNbtSerialization.readItem(CompoundTag).<T> booleanApplies the given function to a list subtag if it is present, converting it to a list of values first.booleanreadLong(@NonNls String key, LongConsumer consumer) Applies the given function to a long subtag if it is present.booleanreadLongArray(@NonNls String key, Consumer<? super long[]> consumer) booleanreadShort(@NonNls String key, ShortConsumer consumer) Applies the given function to an integer subtag if it is present.booleanreadString(@NonNls String key, Consumer<? super String> consumer) Applies the given function to a string subtag if it is present.booleanreadStringList(@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.booleanreadUniqueId(@NonNls String keyMost, @NonNls String keyLeast, Consumer<? super UUID> consumer) Deprecated.booleanreadUniqueId(@NonNls String key, Consumer<? super UUID> consumer) voidOptional<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 voidvalueToString(StringBuilder builder)
-
Constructor Details
-
CompoundTag
public CompoundTag()Creates a new, empty CompoundTag. -
CompoundTag
-
-
Method Details
-
valueToString
- Overrides:
valueToStringin 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 abytesubtag.- Parameters:
key- the key to look up- Returns:
- the tag value
-
getShort
Returns the value of ashortsubtag.- Parameters:
key- the key to look up- Returns:
- the tag value
-
getInt
Returns the value of anintsubtag.- Specified by:
getIntin interfaceDynamicallyTypedMap<String>- Parameters:
key- the key to look up- Returns:
- the tag value
-
getBoolean
Description copied from interface:DynamicallyTypedMapRetrieves an entry as aboolean.- Specified by:
getBooleanin interfaceDynamicallyTypedMap<String>- Parameters:
key- the key to look up- Returns:
- the value as a boolean
-
getBoolean
Returns the boolean value of abytesubtag 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 alongsubtag.- Parameters:
key- the key to look up- Returns:
- the tag value
-
getFloat
Returns the value of afloatsubtag.- Specified by:
getFloatin interfaceDynamicallyTypedMapWithFloats<String>- Parameters:
key- the key to look up- Returns:
- the tag value
-
getDouble
Returns the value of adoublesubtag.- Specified by:
getDoublein 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 aStringsubtag.- Specified by:
getStringin 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 aListsubtag.- 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 ofbytetype.- 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 ofshorttype.- 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 ofinttype.- 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 oflongtype.- 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 offloattype.- 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 ofdoubletype.- 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 ofStringtype.- 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 ofListtype. -
isCompound
Test whether the subtag with the given key is ofCompoundTagtype.- 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 ofListtype with elements of typeCompoundTag.- Parameters:
key- the key to look up- Returns:
- true if the subtag exists and is a
Listwith 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.