mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 19:47:44 +01:00
Added tag default value
This commit is contained in:
parent
9c41a19592
commit
0a7b773aa8
@ -1,11 +1,13 @@
|
||||
package net.minestom.server.tag;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Tag<T> {
|
||||
|
||||
@ -13,6 +15,8 @@ public class Tag<T> {
|
||||
private final Function<NBTCompound, T> readFunction;
|
||||
private final BiConsumer<NBTCompound, T> writeConsumer;
|
||||
|
||||
protected volatile Supplier<T> defaultValue;
|
||||
|
||||
private Tag(@NotNull String key,
|
||||
@NotNull Function<NBTCompound, T> readFunction,
|
||||
@NotNull BiConsumer<NBTCompound, T> writeConsumer) {
|
||||
@ -25,6 +29,20 @@ public class Tag<T> {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Tag<T> defaultValue(@NotNull Supplier<T> defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tag<T> defaultValue(@NotNull T defaultValue) {
|
||||
defaultValue(() -> defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
public @Nullable Supplier<@Nullable T> getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
protected T read(@NotNull NBTCompound nbtCompound) {
|
||||
return readFunction.apply(nbtCompound);
|
||||
}
|
||||
|
@ -5,4 +5,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface TagGetter {
|
||||
<T> @Nullable T getTag(@NotNull Tag<T> tag);
|
||||
|
||||
boolean hasTag(@NotNull Tag<?> tag);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user