mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 19:47:44 +01:00
Add tag comments
This commit is contained in:
parent
1ec631fa5b
commit
429a14e220
@ -9,7 +9,14 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Tag<T> {
|
||||
/**
|
||||
* Represents a key to retrieve or change a value.
|
||||
* <p>
|
||||
* All tags are serializable.
|
||||
*
|
||||
* @param <T> the tag type
|
||||
*/
|
||||
public final class Tag<T> {
|
||||
|
||||
private final String key;
|
||||
private final Function<NBTCompound, T> readFunction;
|
||||
|
7
src/main/java/net/minestom/server/tag/TagHandler.java
Normal file
7
src/main/java/net/minestom/server/tag/TagHandler.java
Normal file
@ -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 {
|
||||
}
|
@ -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 <T> the tag type
|
||||
* @return the read tag, null if not present
|
||||
*/
|
||||
<T> @Nullable T getTag(@NotNull Tag<T> 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
|
||||
|
@ -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 <T> the type to serialize
|
||||
*/
|
||||
public interface TagSerializer<T> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
@ -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 <T> the tag type
|
||||
*/
|
||||
<T> void setTag(@NotNull Tag<T> 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
|
||||
|
Loading…
Reference in New Issue
Block a user