mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 20:07:41 +01:00
parent
3ccdb11aab
commit
4771f99d1d
@ -55,6 +55,16 @@ public interface PersistentDataType<T, Z> {
|
||||
PersistentDataType<Float, Float> FLOAT = new PrimitivePersistentDataType<>(Float.class);
|
||||
PersistentDataType<Double, Double> DOUBLE = new PrimitivePersistentDataType<>(Double.class);
|
||||
|
||||
/*
|
||||
Boolean.
|
||||
*/
|
||||
/**
|
||||
* A convenience implementation to convert between Byte and Boolean as there is
|
||||
* no native implementation for booleans. <br>
|
||||
* Any byte value > 0 is considered to be true.
|
||||
*/
|
||||
PersistentDataType<Byte, Boolean> BOOLEAN = new BooleanPersistentDataType();
|
||||
|
||||
/*
|
||||
String.
|
||||
*/
|
||||
@ -155,4 +165,36 @@ public interface PersistentDataType<T, Z> {
|
||||
return primitive;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience implementation to convert between Byte and Boolean as there is
|
||||
* no native implementation for booleans. <br>
|
||||
* Any byte value > 0 is considered to be true.
|
||||
*/
|
||||
class BooleanPersistentDataType implements PersistentDataType<Byte, Boolean> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Class<Byte> getPrimitiveType() {
|
||||
return byte.class;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Class<Boolean> getComplexType() {
|
||||
return boolean.class;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Byte toPrimitive(@NotNull Boolean complex, @NotNull PersistentDataAdapterContext context) {
|
||||
return (byte) (complex ? 1 : 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean fromPrimitive(@NotNull Byte primitive, @NotNull PersistentDataAdapterContext context) {
|
||||
return primitive != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user