Interface NbtList<TType>

Type Parameters:
TType - - the value type of each NBT tag.
All Superinterfaces:
ClonableWrapper, Iterable<TType>, NbtBase<List<NbtBase<TType>>>

public interface NbtList<TType> extends NbtBase<List<NbtBase<TType>>>, Iterable<TType>
Represents a list of NBT tags of the same type without names.

Use NbtFactory to load or create an instance.

The NbtBase.getValue() method returns a List that will correctly return the content of this NBT list, but may throw an UnsupportedOperationException for any of the write operations.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of every NBT tag in a list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(byte value)
    Add a new byte element to the list.
    void
    add(byte[] value)
    Add a new byte array element to the list.
    void
    add(double value)
    Add a new double element to the list.
    void
    add(int value)
    Add a new integer element to the list.
    void
    add(int[] value)
    Add a new int array element to the list.
    void
    add(long value)
    Add a new long element to the list.
    void
    add(short value)
    Add a new short element to the list.
    void
    add(NbtBase<TType> element)
    Add a NBT list or NBT compound to the list.
    void
    add(String value)
    Add a new string element to the list.
    void
    Deprecated.
    since 1.21.5 lists can be heterogeneous.
    void
    addClosest(Object value, NbtType type)
    Add a value to a typed list by attempting to convert it to the nearest value.
    Retrieve each NBT tag in this list.
    Get the type of each element.
    getValue(int index)
    Retrieve an element by index.
    Iterate over all the elements in this list.
    void
    remove(Object remove)
    Remove a given object from the list.
    void
    Deprecated.
    since 1.21.5 lists can be heterogeneous
    int
    Retrieve the number of elements in this list.

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface com.comphenix.protocol.wrappers.nbt.NbtBase

    accept, deepClone, getHandle, getName, getType, getValue, setName, setValue
  • Field Details

  • Method Details

    • getElementType

      NbtType getElementType()
      Get the type of each element. For heterogeneous lists this will return TAG_COMPOUND.

      This will be TAG_END if the NBT list has just been created.

      Returns:
      Element type.
    • setElementType

      @Deprecated void setElementType(NbtType type)
      Deprecated.
      since 1.21.5 lists can be heterogeneous
      Set the type of each element.

      In 1.21.5 and up lists can be heterogeneous, here the type is only used to convert elements added with addClosest(Object)

      Parameters:
      type - - type of each element.
    • addClosest

      @Deprecated void addClosest(Object value)
      Deprecated.
      since 1.21.5 lists can be heterogeneous. Use addClosest(Object, NbtType)
      Add a value to a typed list by attempting to convert it to the nearest value.

      Note that the list must be typed by setting setElementType(NbtType) before calling this function.

      Parameters:
      value - - the value to add.
    • addClosest

      void addClosest(Object value, NbtType type)
      Add a value to a typed list by attempting to convert it to the nearest value.

      Parameters:
      value - - the value to add.
      type - - the resulting type of the entry
    • add

      void add(NbtBase<TType> element)
      Add a NBT list or NBT compound to the list.
      Parameters:
      element - Element to add
    • add

      void add(String value)
      Add a new string element to the list.
      Parameters:
      value - - the string element to add.
      Throws:
      IllegalArgumentException - If this is not a list of strings.
    • add

      void add(byte value)
      Add a new byte element to the list.
      Parameters:
      value - - the byte element to add.
      Throws:
      IllegalArgumentException - If this is not a list of bytes.
    • add

      void add(short value)
      Add a new short element to the list.
      Parameters:
      value - - the short element to add.
      Throws:
      IllegalArgumentException - If this is not a list of shorts.
    • add

      void add(int value)
      Add a new integer element to the list.
      Parameters:
      value - - the string element to add.
      Throws:
      IllegalArgumentException - If this is not a list of integers.
    • add

      void add(long value)
      Add a new long element to the list.
      Parameters:
      value - - the string element to add.
      Throws:
      IllegalArgumentException - If this is not a list of longs.
    • add

      void add(double value)
      Add a new double element to the list.
      Parameters:
      value - - the double element to add.
      Throws:
      IllegalArgumentException - If this is not a list of doubles.
    • add

      void add(byte[] value)
      Add a new byte array element to the list.
      Parameters:
      value - - the byte array element to add.
      Throws:
      IllegalArgumentException - If this is not a list of byte arrays.
    • add

      void add(int[] value)
      Add a new int array element to the list.
      Parameters:
      value - - the int array element to add.
      Throws:
      IllegalArgumentException - If this is not a list of int arrays.
    • remove

      void remove(Object remove)
      Remove a given object from the list.
      Parameters:
      remove - - the object to remove.
    • getValue

      TType getValue(int index)
      Retrieve an element by index.
      Parameters:
      index - - index of the element to retrieve.
      Returns:
      The element to retrieve.
      Throws:
      IndexOutOfBoundsException - If the index is out of range
    • size

      int size()
      Retrieve the number of elements in this list.
      Returns:
      The number of elements in this list.
    • asCollection

      Collection<NbtBase<TType>> asCollection()
      Retrieve each NBT tag in this list.
      Returns:
      A view of NBT tag in this list.
    • iterator

      Iterator<TType> iterator()
      Iterate over all the elements in this list.
      Specified by:
      iterator in interface Iterable<TType>