Package org.bukkit.persistence
Interface PersistentDataType<T,Z>
- Type Parameters:
T
- the primary object type that is stored in the given tagZ
- the retrieved object type when applying this tag type
- All Known Implementing Classes:
PersistentDataType.PrimitivePersistentDataType
public interface PersistentDataType<T,Z>
This class represents an enum with a generic content type. It defines the
types a custom tag can have.
This interface can be used to create your own custom
PersistentDataType
with different complex types. This may be useful
for the likes of a UUIDTagType:
public class UUIDTagType implements PersistentDataType<byte[], UUID> {
{@literal @Override}
public Class<byte[]> getPrimitiveType() {
return byte[].class;
}
{@literal @Override}
public Class<UUID> getComplexType() {
return UUID.class;
}
{@literal @Override}
public byte[] toPrimitive(UUID complex, PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(complex.getMostSignificantBits());
bb.putLong(complex.getLeastSignificantBits());
return bb.array();
}
{@literal @Override}
public UUID fromPrimitive(byte[] primitive, PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(primitive);
long firstLong = bb.getLong();
long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
}
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A default implementation that simply exists to pass on the retrieved or inserted value to the next layer. -
Field Summary
Modifier and TypeFieldDescriptionstatic PersistentDataType<Byte,Byte>
static PersistentDataType<byte[],byte[]>
static PersistentDataType<Double,Double>
static PersistentDataType<Float,Float>
static PersistentDataType<Integer,Integer>
static PersistentDataType<int[],int[]>
static PersistentDataType<Long,Long>
static PersistentDataType<long[],long[]>
static PersistentDataType<Short,Short>
static PersistentDataType<String,String>
-
Method Summary
Modifier and TypeMethodDescriptionfromPrimitive(T primitive, PersistentDataAdapterContext context)
Creates a complex object based of the passed primitive valueReturns the complex object type the primitive value resembles.Returns the primitive data type of this tag.toPrimitive(Z complex, PersistentDataAdapterContext context)
Returns the primitive data that resembles the complex object passed to this method.
-
Field Details
-
BYTE
-
SHORT
-
INTEGER
-
LONG
-
FLOAT
-
DOUBLE
-
STRING
-
BYTE_ARRAY
-
INTEGER_ARRAY
-
LONG_ARRAY
-
TAG_CONTAINER_ARRAY
static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> TAG_CONTAINER_ARRAY -
TAG_CONTAINER
-
-
Method Details
-
getPrimitiveType
Returns the primitive data type of this tag.- Returns:
- the class
-
getComplexType
Returns the complex object type the primitive value resembles.- Returns:
- the class type
-
toPrimitive
Returns the primitive data that resembles the complex object passed to this method.- Parameters:
complex
- the complex object instancecontext
- the context this operation is running in- Returns:
- the primitive value
-
fromPrimitive
Creates a complex object based of the passed primitive value- Parameters:
primitive
- the primitive valuecontext
- the context this operation is running in- Returns:
- the complex object instance
-