Package com.viaversion.nbt.tag
Class ListTag<T extends Tag>
java.lang.Object
com.viaversion.nbt.tag.ListTag<T>
- Direct Known Subclasses:
MixedListTag
A tag containing a list of tags.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a tag to this list tag.Returns the raw string representation of the value of this tag.copy()Returns a copy of this tag.booleanget(int index) Gets the tag at the given index of this list tag.Gets the element type of the ListTag.intgetTagId()Returns the NBT tag id of this tag type, used in I/O.getValue()Returns the value of this tag.inthashCode()booleanisEmpty()iterator()static ListTag<?> Creates a list tag, possibly of mixed types.static ListTag<?> read(DataInput in, TagLimiter tagLimiter, int nestingLevel) remove(int index) Removes the tag at the given index of this list tag.booleanRemoves a tag from this list tag.Sets the tag at the given index of this list tag.voidSets the value of this tag.intsize()Gets the number of tags in this list tag.stream()toString()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
-
ListTag
Deprecated.useMixedListTagif you need to mix element typesCreates an empty list tag and no defined type. -
ListTag
Creates an empty list tag and type.- Parameters:
type- Tag type of the list.
-
ListTag
Creates a list tag and value. The list tag's type will be set to that of the first tag being added, or null if the given list is empty.- Parameters:
value- The value of the tag.- Throws:
IllegalArgumentException- If all tags in the list are not of the same type.
-
-
Method Details
-
of
Creates a list tag, possibly of mixed types.- Parameters:
value- list of tags, can be mixed- Returns:
- a new list tag
-
read
public static ListTag<?> 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. The list tag's type will be set to that of the first tag being added, or null if the given list is empty.- Parameters:
value- New value of this tag.- Throws:
IllegalArgumentException- If all tags in the list are not of the same type.
-
getElementType
Gets the element type of the ListTag.- Returns:
- The ListTag's element type, or null if the list does not yet have a defined type.
-
add
Adds a tag to this list tag. If the list does not yet have a type, it will be set to the type of the tag being added.- Parameters:
tag- Tag to add. Should not be null.- Returns:
- If the list was changed as a result.
- Throws:
IllegalArgumentException- If the tag's type differs from the list tag's type.
-
remove
Removes a tag from this list tag.- Parameters:
tag- Tag to remove.- Returns:
- If the list contained the tag.
-
get
Gets the tag at the given index of this list tag.- Parameters:
index- Index of the tag.- Returns:
- The tag at the given index.
-
set
Sets the tag at the given index of this list tag.- Parameters:
index- Index of the tag.tag- New tag to set.- Returns:
- The old tag at the given index.
-
remove
Removes the tag at the given index of this list tag.- Parameters:
index- Index of the tag.- Returns:
- The removed tag at the given index.
-
size
public int size()Gets the number of tags in this list tag.- Returns:
- The size of this list tag.
-
isEmpty
public boolean isEmpty() -
stream
-
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
-
copy
Description copied from interface:TagReturns a copy of this tag. -
equals
-
hashCode
public int hashCode() -
getTagId
public int getTagId()Description copied from interface:TagReturns the NBT tag id of this tag type, used in I/O. -
toString
-
MixedListTagif you need to mix element types