mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 12:07:42 +01:00
Add TagHandler#fromCompound
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
ce03c45b5e
commit
3598c73e5a
@ -1,10 +1,35 @@
|
|||||||
package net.minestom.server.tag;
|
package net.minestom.server.tag;
|
||||||
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an element which can read and write {@link Tag tags}.
|
* Represents an element which can read and write {@link Tag tags}.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
public interface TagHandler extends TagReadable, TagWritable {
|
public interface TagHandler extends TagReadable, TagWritable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a nbt compound to a tag handler.
|
||||||
|
* <p>
|
||||||
|
* The returned tag handler is not thread-safe.
|
||||||
|
*
|
||||||
|
* @param compound the compound to convert
|
||||||
|
* @return a {@link TagHandler} capable of writing and reading {@code compound}
|
||||||
|
*/
|
||||||
|
static @NotNull TagHandler fromCompound(@NotNull MutableNBTCompound compound) {
|
||||||
|
return new TagHandler() {
|
||||||
|
@Override
|
||||||
|
public <T> @Nullable T getTag(@NotNull Tag<T> tag) {
|
||||||
|
return tag.read(compound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> void setTag(@NotNull Tag<T> tag, @Nullable T value) {
|
||||||
|
tag.write(compound, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user