mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-08-20 05:14:15 +00:00
#857: Add boolean PersistentDataType
This commit is contained in:
parent
4727d326da
commit
d2b99e567d
1 changed files with 42 additions and 0 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue