Package net.minestom.server.tag
Class Tag<T>
java.lang.Object
net.minestom.server.tag.Tag<T>
- Type Parameters:
T
- the tag type
Represents a key to retrieve or change a value.
All tags are serializable.
-
Method Summary
Modifier and TypeMethodDescriptiondefaultValue
(@NotNull Supplier<T> defaultValue) defaultValue
(T defaultValue) boolean
@NotNull String
getKey()
Returns the key used to navigate inside the holder nbt.int
hashCode()
list()
<R> Tag
<R> static @NotNull Tag
<net.kyori.adventure.nbt.BinaryTag> Creates a flexible tag able to read and write anyBinaryTag
objects.read
(@NotNull net.kyori.adventure.nbt.CompoundBinaryTag nbt) static <T> @NotNull Tag
<T> Structure
(@NotNull String key, @NotNull TagSerializer<T> serializer) Creates a tag containing multiple fields.static <T> @NotNull Tag
<T> Creates a transient tag with the specified key.static <T> @NotNull Tag
<T> View
(@NotNull TagSerializer<T> serializer) Specialized Structure tag affecting the src of the handler (i.e.void
void
writeUnsafe
(net.kyori.adventure.nbt.CompoundBinaryTag.Builder nbtCompound, @Nullable Object value)
-
Method Details
-
getKey
Returns the key used to navigate inside the holder nbt.- Returns:
- the tag key
-
defaultValue
-
defaultValue
-
map
-
list
-
path
-
read
-
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
-
hashCode
public int hashCode() -
Byte
-
Boolean
-
Short
-
Integer
-
Long
-
Float
-
Double
-
String
-
UUID
-
ItemStack
-
Component
-
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 anyBinaryTag
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 keyserializer
- the tag serializer- Returns:
- the created tag
-
View
Specialized Structure tag affecting the src of the handler (i.e. overwrite all its data).Must be used with care.
-
Structure
-
View
-
Transient
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.
-