Module syntaxnbt

Class Tag<T>

java.lang.Object
at.syntaxerror.syntaxnbt.tag.Tag<T>
Type Parameters:
T - type of the value stored in this tag
Direct Known Subclasses:
TagArray, TagCompound, TagEnd, TagList, TagNumber, TagString

public abstract class Tag<T> extends Object
An NBT Tag consisting of a type and a value
Author:
SyntaxError404
  • Constructor Details

    • Tag

      protected Tag(TagType type, T value)
      Constructs a new tag with a type and an initial value
      Parameters:
      type - type of this tag
      value - initial value
  • Method Details

    • is

      public boolean is(TagType type)
      Tests if the type of this tag matches the type specified
      Parameters:
      type - the type to be checked
      Returns:
      whether the types match
    • isCompound

      public boolean isCompound()
      Tests if this tag is a TagCompound
      Returns:
      whether this tag is a compound
    • isList

      public boolean isList()
      Tests if this tag is a TagList
      Returns:
      whether this tag is a list
      See Also:
    • isList

      public boolean isList(TagType componentType)
      Tests if this tag is a TagList containing only elements of type componentType
      Parameters:
      componentType - expected type for list elements
      Returns:
      whether this tag is a list with children of type componentType
      See Also:
    • isArray

      public boolean isArray()
      Returns:
      whether this tag is an array
    • isString

      public boolean isString()
      Tests if this tag is a TagString
      Returns:
      whether this tag is a string
    • isNumber

      public boolean isNumber()
      Returns:
      whether this tag is a number
    • isInteger

      public boolean isInteger()
      Tests if this tag is a TagNumber denoting an integer (TagType.BYTE, TagType.SHORT, TagType.INT, or TagType.LONG)
      Returns:
      whether this tag is an integer
    • isFloat

      public boolean isFloat()
      Tests if this tag is a TagNumber denoting a floating point number (TagType.FLOAT or TagType.DOUBLE)
      Returns:
      whether this tag is a float
    • cast

      public <N extends Tag<?>> N cast()
      Casts this tag to the requested type, if possible
      Type Parameters:
      N - the type of the tag
      Returns:
      this tag
      Throws:
      ClassCastException - if casting failed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compare

      protected boolean compare(Tag<T> tag)
      Compares two tags for equality
      Parameters:
      tag - tag to compare to
      Returns:
      whether the tags are equal
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getType

      @NonNull public @NonNull TagType getType()
      Returns the type of this tag
      Returns:
      the type of this tag
    • getValue

      @NonNull public T getValue()
      Returns the value stored in this tag
      Returns:
      the value stored in this tag
    • setValue

      public void setValue(@NonNull T value)
      Overrides the value stored in this tag
      Parameters:
      value - value to be stored