From 429a14e22028d49eace4c091544e55f19dffeaa9 Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 17 May 2021 15:14:16 +0200 Subject: [PATCH] Add tag comments --- .../java/net/minestom/server/tag/Tag.java | 9 +++++++- .../net/minestom/server/tag/TagHandler.java | 7 ++++++ .../net/minestom/server/tag/TagReader.java | 23 +++++++++++++++++++ .../minestom/server/tag/TagSerializer.java | 17 ++++++++++++++ .../net/minestom/server/tag/TagWriter.java | 17 ++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/minestom/server/tag/TagHandler.java diff --git a/src/main/java/net/minestom/server/tag/Tag.java b/src/main/java/net/minestom/server/tag/Tag.java index 49c920690..9ef0bc584 100644 --- a/src/main/java/net/minestom/server/tag/Tag.java +++ b/src/main/java/net/minestom/server/tag/Tag.java @@ -9,7 +9,14 @@ import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Supplier; -public class Tag { +/** + * Represents a key to retrieve or change a value. + *

+ * All tags are serializable. + * + * @param the tag type + */ +public final class Tag { private final String key; private final Function readFunction; diff --git a/src/main/java/net/minestom/server/tag/TagHandler.java b/src/main/java/net/minestom/server/tag/TagHandler.java new file mode 100644 index 000000000..c5b9632cf --- /dev/null +++ b/src/main/java/net/minestom/server/tag/TagHandler.java @@ -0,0 +1,7 @@ +package net.minestom.server.tag; + +/** + * Represents an element which can read and write {@link Tag tags}. + */ +public interface TagHandler extends TagReader, TagWriter { +} diff --git a/src/main/java/net/minestom/server/tag/TagReader.java b/src/main/java/net/minestom/server/tag/TagReader.java index b29f944b6..79338c0df 100644 --- a/src/main/java/net/minestom/server/tag/TagReader.java +++ b/src/main/java/net/minestom/server/tag/TagReader.java @@ -4,11 +4,34 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBTCompound; +/** + * Represents an element which can read {@link Tag tags}. + */ public interface TagReader { + + /** + * Reads the specified tag. + * + * @param tag the tag to read + * @param the tag type + * @return the read tag, null if not present + */ @Nullable T getTag(@NotNull Tag tag); + /** + * Returns if a tag is present. + * + * @param tag the tag to check + * @return true if the tag is present, false otherwise + */ boolean hasTag(@NotNull Tag tag); + /** + * Converts an nbt compound to a tag reader. + * + * @param compound the compound to convert + * @return a {@link TagReader} capable of reading {@code compound} + */ static @NotNull TagReader fromCompound(@NotNull NBTCompound compound) { return new TagReader() { @Override diff --git a/src/main/java/net/minestom/server/tag/TagSerializer.java b/src/main/java/net/minestom/server/tag/TagSerializer.java index 26692c591..151d1de0e 100644 --- a/src/main/java/net/minestom/server/tag/TagSerializer.java +++ b/src/main/java/net/minestom/server/tag/TagSerializer.java @@ -3,9 +3,26 @@ package net.minestom.server.tag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Interface used to create custom types compatible with {@link Tag#Custom(String, TagSerializer)}. + * + * @param the type to serialize + */ public interface TagSerializer { + /** + * Reads the custom tag from a {@link TagReader}. + * + * @param reader the reader + * @return the deserialized value + */ @Nullable T read(@NotNull TagReader reader); + /** + * Writes the custom tag to a {@link TagWriter}. + * + * @param writer the writer + * @param value the value to serialize + */ void write(@NotNull TagWriter writer, @NotNull T value); } diff --git a/src/main/java/net/minestom/server/tag/TagWriter.java b/src/main/java/net/minestom/server/tag/TagWriter.java index c88504c6d..8b85d5151 100644 --- a/src/main/java/net/minestom/server/tag/TagWriter.java +++ b/src/main/java/net/minestom/server/tag/TagWriter.java @@ -4,9 +4,26 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBTCompound; +/** + * Represents an element which can write {@link Tag tags}. + */ public interface TagWriter { + + /** + * Writes the specified type. + * + * @param tag the tag to write + * @param value the tag value, null to remove + * @param the tag type + */ void setTag(@NotNull Tag tag, @Nullable T value); + /** + * Converts an nbt compound to a tag writer. + * + * @param compound the compound to convert + * @return a {@link TagWriter} capable of writing {@code compound} + */ static @NotNull TagWriter fromCompound(@NotNull NBTCompound compound) { return new TagWriter() { @Override