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

      @NotNull public @NotNull 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(@NotNull @NotNull Supplier<T> defaultValue)
    • defaultValue

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

      @Contract(value="_, _ -> new", pure=true) public <R> Tag<R> map(@NotNull @NotNull Function<T,R> readMap, @NotNull @NotNull 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(@NotNull @NotNull String @Nullable ... path)
    • read

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

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

      public void writeUnsafe(@NotNull 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

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

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

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

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

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

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

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

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

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

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

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

      @NotNull public static @NotNull Tag<net.kyori.adventure.nbt.BinaryTag> NBT(@NotNull @NotNull 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

      @NotNull public static <T> @NotNull Tag<T> Structure(@NotNull @NotNull String key, @NotNull @NotNull 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

      @NotNull public static <T> @NotNull Tag<T> View(@NotNull @NotNull 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 @NotNull public static <T extends Record> @NotNull Tag<T> Structure(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type)
    • View

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

      @NotNull public static <T> @NotNull Tag<T> Transient(@NotNull @NotNull 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.