mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-07 15:42:19 -07:00
@@ -55,6 +55,16 @@ public interface PersistentDataType<T, Z> {
|
|||||||
PersistentDataType<Float, Float> FLOAT = new PrimitivePersistentDataType<>(Float.class);
|
PersistentDataType<Float, Float> FLOAT = new PrimitivePersistentDataType<>(Float.class);
|
||||||
PersistentDataType<Double, Double> DOUBLE = new PrimitivePersistentDataType<>(Double.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.
|
String.
|
||||||
*/
|
*/
|
||||||
@@ -155,4 +165,36 @@ public interface PersistentDataType<T, Z> {
|
|||||||
return primitive;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user