程序包 org.bukkit.persistence

# 接口 PersistentDataType<P,C>

类型参数:
  `P` - the primary object type that is stored in the given tag
  `C` - the retrieved object type when applying this tag type

所有已知子接口:
  `ListPersistentDataType<P,C>`

所有已知实现类:
  `PersistentDataType.BooleanPersistentDataType`, `PersistentDataType.PrimitivePersistentDataType`

public interface PersistentDataType<P,C>
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> {

             @Override
             public Class<byte[]> getPrimitiveType() {
                 return byte[].class;
             }

             @Override
             public Class<UUID> getComplexType() {
                 return UUID.class;
             }

             @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();
             }

             @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);
             }
         }

Any plugin owned implementation of this interface is required to define one of the existing primitive types found in this interface. Notably `BOOLEAN` is not a primitive type but a convenience type.

- ## 嵌套类概要

  嵌套类
  修饰符和类型
  接口
  说明
  `static class`
  `PersistentDataType.BooleanPersistentDataType`
  A convenience implementation to convert between Byte and Boolean as there is no native implementation for booleans.
  `static class`
  `PersistentDataType.PrimitivePersistentDataType<P>`
  A default implementation that simply exists to pass on the retrieved or inserted value to the next layer.

- ## 字段概要

  字段
  修饰符和类型
  字段
  说明
  `static final PersistentDataType<Byte,Boolean>`
  `BOOLEAN`
  A convenience implementation to convert between Byte and Boolean as there is no native implementation for booleans.
  `static final PersistentDataType<Byte,Byte>`
  `BYTE`
  `static final PersistentDataType<byte[],byte[]>`
  `BYTE_ARRAY`
  `static final PersistentDataType<Double,Double>`
  `DOUBLE`
  `static final PersistentDataType<Float,Float>`
  `FLOAT`
  `static final PersistentDataType<Integer,Integer>`
  `INTEGER`
  `static final PersistentDataType<int[],int[]>`
  `INTEGER_ARRAY`
  `static final ListPersistentDataTypeProvider`
  `LIST`
  A data type provider type that itself cannot be used as a `PersistentDataType`.
  `static final PersistentDataType<Long,Long>`
  `LONG`
  `static final PersistentDataType<long[],long[]>`
  `LONG_ARRAY`
  `static final PersistentDataType<Short,Short>`
  `SHORT`
  `static final PersistentDataType<String,String>`
  `STRING`
  `static final PersistentDataType<PersistentDataContainer,PersistentDataContainer>`
  `TAG_CONTAINER`
  `static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]>`
  `TAG_CONTAINER_ARRAY`
  已过时。
  Use `LIST`'s `ListPersistentDataTypeProvider.dataContainers()` instead as `ListPersistentDataType`s offer full support for primitive types, such as the `PersistentDataContainer`.

- ## 方法概要

  修饰符和类型
  方法
  说明
  `C`
  `fromPrimitive(P primitive, @NotNull PersistentDataAdapterContext context)`
  Creates a complex object based of the passed primitive value
  `@NotNull Class<C>`
  `getComplexType()`
  Returns the complex object type the primitive value resembles.
  `@NotNull Class<P>`
  `getPrimitiveType()`
  Returns the primitive data type of this tag.
  `P`
  `toPrimitive(C complex, @NotNull PersistentDataAdapterContext context)`
  Returns the primitive data that resembles the complex object passed to this method.

- ## 字段详细资料

  - ### BYTE

    static final PersistentDataType<Byte,Byte> BYTE

  - ### SHORT

    static final PersistentDataType<Short,Short> SHORT

  - ### INTEGER

    static final PersistentDataType<Integer,Integer> INTEGER

  - ### LONG

    static final PersistentDataType<Long,Long> LONG

  - ### FLOAT

    static final PersistentDataType<Float,Float> FLOAT

  - ### DOUBLE

    static final PersistentDataType<Double,Double> DOUBLE

  - ### BOOLEAN

    static final PersistentDataType<Byte,Boolean> BOOLEAN
    A convenience implementation to convert between Byte and Boolean as there is no native implementation for booleans.
    Any byte value not equal to 0 is considered to be true.

  - ### STRING

    static final PersistentDataType<String,String> STRING

  - ### BYTE_ARRAY

    static final PersistentDataType<byte[],byte[]> BYTE_ARRAY

  - ### INTEGER_ARRAY

    static final PersistentDataType<int[],int[]> INTEGER_ARRAY

  - ### LONG_ARRAY

    static final PersistentDataType<long[],long[]> LONG_ARRAY

  - ### TAG_CONTAINER_ARRAY

    @Deprecated static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> TAG_CONTAINER_ARRAY
    已过时。
    Use `LIST`'s `ListPersistentDataTypeProvider.dataContainers()` instead as `ListPersistentDataType`s offer full support for primitive types, such as the `PersistentDataContainer`.

  - ### TAG_CONTAINER

    static final PersistentDataType<PersistentDataContainer,PersistentDataContainer> TAG_CONTAINER

  - ### LIST

    static final ListPersistentDataTypeProvider LIST
    A data type provider type that itself cannot be used as a `PersistentDataType`. `ListPersistentDataTypeProvider` exposes shared persistent data types for storing lists of other data types, however.

    Its existence in the `PersistentDataType` interface does not permit `List` as a primitive type in combination with a plain `PersistentDataType`. `List`s are only valid primitive types when used via a `ListPersistentDataType`.

    另请参阅:
      - `ListPersistentDataTypeProvider`

- ## 方法详细资料

  - ### getPrimitiveType

    @NotNull @NotNull Class<P> getPrimitiveType()
    Returns the primitive data type of this tag.
    返回:
      the class

  - ### getComplexType

    @NotNull @NotNull Class<C> getComplexType()
    Returns the complex object type the primitive value resembles.
    返回:
      the class type

  - ### toPrimitive

    @NotNull P toPrimitive(@NotNull C complex, @NotNull @NotNull PersistentDataAdapterContext context)
    Returns the primitive data that resembles the complex object passed to this method.
    参数:
      `complex` - the complex object instance
      `context` - the context this operation is running in
    返回:
      the primitive value

  - ### fromPrimitive

    @NotNull C fromPrimitive(@NotNull P primitive, @NotNull @NotNull PersistentDataAdapterContext context)
    Creates a complex object based of the passed primitive value
    参数:
      `primitive` - the primitive value
      `context` - the context this operation is running in
    返回:
      the complex object instance