mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 12:07:42 +01:00
Added TagSerializer
This commit is contained in:
parent
1715e55b4d
commit
d3b4b2ac56
@ -133,4 +133,25 @@ public class Tag<T> {
|
|||||||
nbtCompound -> nbtCompound.getLongArray(key),
|
nbtCompound -> nbtCompound.getLongArray(key),
|
||||||
(nbtCompound, value) -> nbtCompound.setLongArray(key, value));
|
(nbtCompound, value) -> nbtCompound.setLongArray(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> @NotNull Tag<T> Custom(@NotNull String key, @NotNull TagSerializer<T> serializer) {
|
||||||
|
return new Tag<>(key,
|
||||||
|
nbtCompound -> serializer.read(new TagReader() {
|
||||||
|
@Override
|
||||||
|
public <T> @Nullable T getTag(@NotNull Tag<T> tag) {
|
||||||
|
return tag.read(nbtCompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTag(@NotNull Tag<?> tag) {
|
||||||
|
return nbtCompound.containsKey(tag.key);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
(nbtCompound, value) -> new TagWriter() {
|
||||||
|
@Override
|
||||||
|
public <T> void setTag(@NotNull Tag<T> tag, @Nullable T value) {
|
||||||
|
tag.write(nbtCompound, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package net.minestom.server.tag;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface TagGetter {
|
public interface TagReader {
|
||||||
<T> @Nullable T getTag(@NotNull Tag<T> tag);
|
<T> @Nullable T getTag(@NotNull Tag<T> tag);
|
||||||
|
|
||||||
boolean hasTag(@NotNull Tag<?> tag);
|
boolean hasTag(@NotNull Tag<?> tag);
|
11
src/main/java/net/minestom/server/tag/TagSerializer.java
Normal file
11
src/main/java/net/minestom/server/tag/TagSerializer.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package net.minestom.server.tag;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface TagSerializer<T> {
|
||||||
|
|
||||||
|
@Nullable T read(@NotNull TagReader reader);
|
||||||
|
|
||||||
|
void write(@NotNull TagWriter writer, @NotNull T value);
|
||||||
|
}
|
@ -3,6 +3,6 @@ package net.minestom.server.tag;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface TagSetter {
|
public interface TagWriter {
|
||||||
<T> void setTag(@NotNull Tag<T> tag, @Nullable T value);
|
<T> void setTag(@NotNull Tag<T> tag, @Nullable T value);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user