2021-05-17 12:34:45 +02:00
|
|
|
package net.minestom.server.tag;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-05-17 14:05:03 +02:00
|
|
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
2021-05-17 12:34:45 +02:00
|
|
|
|
2021-05-17 15:14:16 +02:00
|
|
|
/**
|
|
|
|
* Represents an element which can write {@link Tag tags}.
|
|
|
|
*/
|
2021-05-17 14:02:14 +02:00
|
|
|
public interface TagWriter {
|
2021-05-17 15:14:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the specified type.
|
|
|
|
*
|
|
|
|
* @param tag the tag to write
|
|
|
|
* @param value the tag value, null to remove
|
|
|
|
* @param <T> the tag type
|
|
|
|
*/
|
2021-05-17 12:34:45 +02:00
|
|
|
<T> void setTag(@NotNull Tag<T> tag, @Nullable T value);
|
2021-05-17 14:05:03 +02:00
|
|
|
|
2021-05-17 15:14:16 +02:00
|
|
|
/**
|
|
|
|
* Converts an nbt compound to a tag writer.
|
|
|
|
*
|
|
|
|
* @param compound the compound to convert
|
|
|
|
* @return a {@link TagWriter} capable of writing {@code compound}
|
|
|
|
*/
|
2021-05-17 14:05:03 +02:00
|
|
|
static @NotNull TagWriter fromCompound(@NotNull NBTCompound compound) {
|
|
|
|
return new TagWriter() {
|
|
|
|
@Override
|
|
|
|
public <T> void setTag(@NotNull Tag<T> tag, @Nullable T value) {
|
|
|
|
tag.write(compound, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-05-17 12:34:45 +02:00
|
|
|
}
|