mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 12:07:42 +01:00
No need to expose tag default value
This commit is contained in:
parent
429a14e220
commit
9255adb7ec
@ -21,8 +21,7 @@ public final class Tag<T> {
|
|||||||
private final String key;
|
private final String key;
|
||||||
private final Function<NBTCompound, T> readFunction;
|
private final Function<NBTCompound, T> readFunction;
|
||||||
private final BiConsumer<NBTCompound, T> writeConsumer;
|
private final BiConsumer<NBTCompound, T> writeConsumer;
|
||||||
|
private volatile Supplier<T> defaultValue;
|
||||||
protected volatile Supplier<T> defaultValue;
|
|
||||||
|
|
||||||
private Tag(@NotNull String key,
|
private Tag(@NotNull String key,
|
||||||
@NotNull Function<NBTCompound, T> readFunction,
|
@NotNull Function<NBTCompound, T> readFunction,
|
||||||
@ -46,15 +45,12 @@ public final class Tag<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Supplier<@Nullable T> getDefaultValue() {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable T read(@NotNull NBTCompound nbtCompound) {
|
public @Nullable T read(@NotNull NBTCompound nbtCompound) {
|
||||||
if (nbtCompound.containsKey(key)) {
|
if (nbtCompound.containsKey(key)) {
|
||||||
return readFunction.apply(nbtCompound);
|
return readFunction.apply(nbtCompound);
|
||||||
} else {
|
} else {
|
||||||
return defaultValue != null ? defaultValue.get() : null;
|
final var supplier = defaultValue;
|
||||||
|
return supplier != null ? supplier.get() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user