Class Tag<T>

java.lang.Object
net.minestom.server.tag.Tag<T>
Type Parameters:
T - the tag type

@NonExtendable public class Tag<T> extends Object
Represents a key to retrieve or change a value.

All tags are serializable.

  • Method Details

    • getKey

      public String getKey()
      Returns the key used to navigate inside the holder nbt.
      Returns:
      the tag key
    • defaultValue

      @Contract(value="_ -> new", pure=true) public Tag<T> defaultValue(Supplier<T> defaultValue)
    • defaultValue

      @Contract(value="_ -> new", pure=true) public Tag<T> defaultValue(T defaultValue)
    • map

      @Contract(value="_, _ -> new", pure=true) public <R> Tag<R> map(Function<T,R> readMap, Function<R,T> writeMap)
    • list

      @Contract(value="-> new", pure=true) public Tag<List<T>> list()
    • path

      @Contract(value="_ -> new", pure=true) public Tag<T> path(String @Nullable ... path)
    • read

      @Nullable public T read(net.kyori.adventure.nbt.CompoundBinaryTag nbt)
    • write

      public void write(net.kyori.adventure.nbt.CompoundBinaryTag.Builder nbtCompound, @Nullable T value)
    • writeUnsafe

      public void writeUnsafe(net.kyori.adventure.nbt.CompoundBinaryTag.Builder nbtCompound, @Nullable @Nullable Object value)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • Byte

      public static Tag<Byte> Byte(String key)
    • Boolean

      public static Tag<Boolean> Boolean(String key)
    • Short

      public static Tag<Short> Short(String key)
    • Integer

      public static Tag<Integer> Integer(String key)
    • Long

      public static Tag<Long> Long(String key)
    • Float

      public static Tag<Float> Float(String key)
    • Double

      public static Tag<Double> Double(String key)
    • String

      public static Tag<String> String(String key)
    • UUID

      public static Tag<UUID> UUID(String key)
    • ItemStack

      public static Tag<ItemStack> ItemStack(String key)
    • Component

      public static Tag<Component> Component(String key)
    • NBT

      public static Tag<net.kyori.adventure.nbt.BinaryTag> NBT(String key)
      Creates a flexible tag able to read and write any BinaryTag objects.

      Specialized tags are recommended if the type is known as conversion will be required both way (read and write).

    • Structure

      public static <T> Tag<T> Structure(String key, TagSerializer<T> serializer)
      Creates a tag containing multiple fields.

      Those fields cannot be modified from an outside tag. (This is to prevent the backed object from becoming out of sync)

      Type Parameters:
      T - the tag type
      Parameters:
      key - the tag key
      serializer - the tag serializer
      Returns:
      the created tag
    • View

      public static <T> Tag<T> View(TagSerializer<T> serializer)
      Specialized Structure tag affecting the src of the handler (i.e. overwrite all its data).

      Must be used with care.

    • Structure

      @Experimental public static <T extends Record> Tag<T> Structure(String key, Class<T> type)
    • View

      @Experimental public static <T extends Record> Tag<T> View(Class<T> type)
    • Transient

      public static <T> Tag<T> Transient(String key)
      Creates a transient tag with the specified key. This tag does not get serialized to NBT (Named Binary Tag) format and is not sent to the client. Unlike other tags, which are serialized, transient tags are used for temporary data that only needs to exist on the server side.
      Type Parameters:
      T - The type of the tag's value.
      Parameters:
      key - The key.
      Returns:
      A transient tag with the key.