Package com.viaversion.nbt.tag
Class CompoundTag
java.lang.Object
com.viaversion.nbt.tag.CompoundTag
A compound tag containing other tags.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a tag.CompoundTag(LinkedHashMap<String, Tag> value) Creates a tag without wrapping the map.CompoundTag(Map<String, Tag> value) Creates a tag. -
Method Summary
Modifier and TypeMethodDescriptionReturns the raw string representation of the value of this tag.voidclear()Clears all tags from this compound tag.booleanChecks whether the compound tag contains a tag.copy()Returns a copy of this tag.entrySet()Gets the entry set of this compound tag.boolean@Nullable TagReturns a tag by name if present.booleangetBoolean(String tagName) booleangetBoolean(String tagName, boolean def) bytebyte@Nullable ByteArrayTaggetByteArrayTag(String tagName) bytegetByteStrict(String tagName) Returns the value of the byte tag if the tag exists and is a ByteTag, or0.bytegetByteStrict(String tagName, byte def) Returns the value of the byte tag if the tag exists and is a ByteTag, ordef.@Nullable ByteTaggetByteTag(String tagName) @Nullable CompoundTaggetCompoundTag(String tagName) doubledoubledoublegetDoubleStrict(String tagName) Returns the value of the double tag if the tag exists and is a DoubleTag, or0D.doublegetDoubleStrict(String tagName, double def) Returns the value of the double tag if the tag exists and is a DoubleTag, ordef.@Nullable DoubleTaggetDoubleTag(String tagName) floatfloatfloatgetFloatStrict(String tagName) Returns the value of the float tag if the tag exists and is a FloatTag, or0F.floatgetFloatStrict(String tagName, float def) Returns the value of the float tag if the tag exists and is a FloatTag, ordef.@Nullable FloatTaggetFloatTag(String tagName) intint@Nullable IntArrayTaggetIntArrayTag(String tagName) intgetIntStrict(String tagName) Returns the value of the int tag if the tag exists and is an IntTag, or0.intgetIntStrict(String tagName, int def) Returns the value of the int tag if the tag exists and is an IntTag, ordef.@Nullable IntTag@Nullable ListTag<?> getListTag(String tagName) getListTag(String tagName, Class<T> type) longlong@Nullable LongArrayTaggetLongArrayTag(String tagName) longgetLongStrict(String tagName) Returns the value of the long tag if the tag exists and is a LongTag, or0L.longgetLongStrict(String tagName, long def) Returns the value of the long tag if the tag exists and is a LongTag, ordef.@Nullable LongTaggetLongTag(String tagName) getNumberListTag(String tagName) @Nullable NumberTaggetNumberTag(String tagName) shortshortshortgetShortStrict(String tagName) Returns the value of the short tag if the tag exists and is a ShortTag, or0.shortgetShortStrict(String tagName, short def) Returns the value of the short tag if the tag exists and is a ShortTag, ordef.@Nullable ShortTaggetShortTag(String tagName) @Nullable String@Nullable String@Nullable StringTaggetStringTag(String tagName) intgetTagId()Returns the NBT tag id of this tag type, used in I/O.<T extends Tag>
TgetUnchecked(String tagName) Returns a tag by name if present.getValue()Returns the value of this tag.inthashCode()booleanisEmpty()Checks whether the compound tag is empty.iterator()keySet()Gets a set of keys in this compound tag.@Nullable TagPuts the tag into this compound tag.voidputAll(CompoundTag compoundTag) voidputBoolean(String tagName, boolean value) voidvoidvoidvoidvoidvoidvoidstatic CompoundTagread(DataInput in, TagLimiter tagLimiter, int nestingLevel) @Nullable TagRemoves a tag from this compound tag.<T extends Tag>
TremoveUnchecked(String tagName) Removes a tag from this compound tag.voidsetValue(LinkedHashMap<String, Tag> value) Sets the value of this tag without wrapping the map.voidSets the value of this tag.intsize()Gets the number of tags in this compound tag.toString()values()Gets a collection of tags in this compound tag.voidwrite(DataOutput out) Writes this tag to an output stream.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ID
public static final int ID- See Also:
-
-
Constructor Details
-
CompoundTag
public CompoundTag()Creates a tag. -
CompoundTag
Creates a tag.- Parameters:
value- The value of the tag.
-
CompoundTag
Creates a tag without wrapping the map.- Parameters:
value- The value of the tag.
-
-
Method Details
-
read
public static CompoundTag read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException - Throws:
IOException
-
getValue
Description copied from interface:TagReturns the value of this tag. -
asRawString
Description copied from interface:TagReturns the raw string representation of the value of this tag. For SNBT, useSNBT.serialize(Tag).- Specified by:
asRawStringin interfaceTag- Returns:
- raw string representation of the value of this tag
-
setValue
Sets the value of this tag.- Parameters:
value- New value of this tag.
-
setValue
Sets the value of this tag without wrapping the map.- Parameters:
value- New value of this tag.
-
isEmpty
public boolean isEmpty()Checks whether the compound tag is empty.- Returns:
- Whether the compound tag is empty.
-
contains
Checks whether the compound tag contains a tag.- Parameters:
tagName- Name of the tag to check for.- Returns:
- Whether the compound tag contains a tag.
-
get
Returns a tag by name if present.This will have its generic removed and instead return a raw tag in the future.
- Parameters:
tagName- key of the tag- Returns:
- tag if present, else null
- See Also:
-
getUnchecked
Returns a tag by name if present.- Type Parameters:
T- type of the tag- Parameters:
tagName- key of the tag- Returns:
- tag if present, else null
-
getStringTag
-
getCompoundTag
-
getListTag
-
getListTag
-
getNumberListTag
-
getIntTag
-
getLongTag
-
getShortTag
-
getByteTag
-
getFloatTag
-
getDoubleTag
-
getNumberTag
-
getByteArrayTag
-
getIntArrayTag
-
getLongArrayTag
-
getString
-
getString
-
getInt
-
getInt
-
getLong
-
getLong
-
getShort
-
getShort
-
getByte
-
getByte
-
getFloat
-
getFloat
-
getDouble
-
getDouble
-
getBoolean
-
getBoolean
-
getIntStrict
Returns the value of the int tag if the tag exists and is an IntTag, or0. UnlikegetInt(String), this does not get the int value from other number tags.- Parameters:
tagName- tag name- Returns:
- int if present, or
0 - See Also:
-
getIntStrict
Returns the value of the int tag if the tag exists and is an IntTag, ordef. UnlikegetInt(String, int), this does not get the int value from other number tags.- Parameters:
tagName- tag name- Returns:
- int if present, or
def - See Also:
-
getLongStrict
Returns the value of the long tag if the tag exists and is a LongTag, or0L. UnlikegetLong(String), this does not get the long value from other number tags.- Parameters:
tagName- tag name- Returns:
- long if present, or
0L - See Also:
-
getLongStrict
Returns the value of the long tag if the tag exists and is a LongTag, ordef. UnlikegetLong(String, long), this does not get the long value from other number tags.- Parameters:
tagName- tag name- Returns:
- long if present, or
def - See Also:
-
getShortStrict
Returns the value of the short tag if the tag exists and is a ShortTag, or0. UnlikegetShort(String), this does not get the short value from other number tags.- Parameters:
tagName- tag name- Returns:
- short if present, or
0 - See Also:
-
getShortStrict
Returns the value of the short tag if the tag exists and is a ShortTag, ordef. UnlikegetShort(String, short), this does not get the short value from other number tags.- Parameters:
tagName- tag name- Returns:
- short if present, or
def - See Also:
-
getByteStrict
Returns the value of the byte tag if the tag exists and is a ByteTag, or0. UnlikegetByte(String), this does not get the byte value from other number tags.- Parameters:
tagName- tag name- Returns:
- byte if present, or
0 - See Also:
-
getByteStrict
Returns the value of the byte tag if the tag exists and is a ByteTag, ordef. UnlikegetByte(String, byte), this does not get the byte value from other number tags.- Parameters:
tagName- tag name- Returns:
- byte if present, or
def - See Also:
-
getFloatStrict
Returns the value of the float tag if the tag exists and is a FloatTag, or0F. UnlikegetFloat(String), this does not get the float value from other number tags.- Parameters:
tagName- tag name- Returns:
- float if present, or
0F - See Also:
-
getFloatStrict
Returns the value of the float tag if the tag exists and is a FloatTag, ordef. UnlikegetFloat(String, float), this does not get the float value from other number tags.- Parameters:
tagName- tag name- Returns:
- float if present, or
def - See Also:
-
getDoubleStrict
Returns the value of the double tag if the tag exists and is a DoubleTag, or0D. UnlikegetDouble(String), this does not get the double value from other number tags.- Parameters:
tagName- tag name- Returns:
- double if present, or
0D - See Also:
-
getDoubleStrict
Returns the value of the double tag if the tag exists and is a DoubleTag, ordef. UnlikegetDouble(String, double), this does not get the double value from other number tags.- Parameters:
tagName- tag name- Returns:
- double if present, or
def - See Also:
-
put
Puts the tag into this compound tag.This will have its generic removed and instead return a raw tag in the future.
- Parameters:
tagName- Name of the tag.tag- Tag to put into this compound tag.- Returns:
- The previous tag associated with its name, or null if there wasn't one.
-
putString
-
putByte
-
putInt
-
putShort
-
putLong
-
putFloat
-
putDouble
-
putBoolean
-
putAll
-
remove
Removes a tag from this compound tag.This will have its generic removed and instead return a raw tag in the future.
- Parameters:
tagName- Name of the tag to remove.- Returns:
- The removed tag.
- See Also:
-
removeUnchecked
Removes a tag from this compound tag.- Type Parameters:
T- Type of tag to remove.- Parameters:
tagName- Name of the tag to remove.- Returns:
- The removed tag.
-
keySet
Gets a set of keys in this compound tag.- Returns:
- The compound tag's key set.
-
values
Gets a collection of tags in this compound tag.- Returns:
- This compound tag's tags.
-
entrySet
Gets the entry set of this compound tag.- Returns:
- The compound tag's entry set.
-
size
public int size()Gets the number of tags in this compound tag.- Returns:
- This compound tag's size.
-
clear
public void clear()Clears all tags from this compound tag. -
iterator
-
write
Description copied from interface:TagWrites this tag to an output stream.- Specified by:
writein interfaceTag- Parameters:
out- data output to write to- Throws:
IOException- if an I/O error occurs
-
equals
-
hashCode
public int hashCode() -
copy
Description copied from interface:TagReturns a copy of this tag. -
getTagId
public int getTagId()Description copied from interface:TagReturns the NBT tag id of this tag type, used in I/O. -
toString
-