接口 PersistentDataContainer
-
方法概要
修饰符和类型方法说明voidcopyTo(@NotNull PersistentDataContainer other, boolean replace) 将所有值从此PersistentDataContainer复制到提供的容器。<P,C> C get(@NotNull NamespacedKey key, @NotNull PersistentDataType<P, C> type) 返回存储在PersistentDataHolder实例上的元数据值。返回此标签容器使用的适配器上下文。getKeys()获取此PersistentDataContainer实例上存在的键集。<P,C> C getOrDefault(@NotNull NamespacedKey key, @NotNull PersistentDataType<P, C> type, C defaultValue) 返回存储在PersistentDataHolder实例上的元数据值。booleanhas(@NotNull NamespacedKey key) 返回持久元数据提供者是否注册了匹配所提供参数的元数据。<P,C> boolean has(@NotNull NamespacedKey key, @NotNull PersistentDataType<P, C> type) 返回持久元数据提供者是否注册了匹配所提供参数的元数据。booleanisEmpty()返回容器实例是否为空,即其中没有条目。voidremove(@NotNull NamespacedKey key) 从PersistentDataHolder实例中移除自定义键。<P,C> void set(@NotNull NamespacedKey key, @NotNull PersistentDataType<P, C> type, C value) 在PersistentDataHolder实例上存储元数据值。
-
方法详细资料
-
set
<P,C> void set(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<P, C> type, @NotNull C value) 在PersistentDataHolder实例上存储元数据值。此 API 不能用于操纵 Minecraft 数据,因为值将使用您的命名空间存储。此方法将覆盖
PersistentDataHolder在提供的键下可能已存储的任何现有值。原文: Stores a metadata value on the
PersistentDataHolderinstance.This API cannot be used to manipulate minecraft data, as the values will be stored using your namespace. This method will override any existing value the
PersistentDataHoldermay have stored under the provided key.- 类型参数:
P- 标签值的通用 Java 类型C- 要存储的对象的通用类型- 参数:
key- 此值将存储在的键type- 此标签使用的类型value- 要存储在标签中的值- 抛出:
IllegalArgumentException- 如果键为 nullIllegalArgumentException- 如果类型为 nullIllegalArgumentException- 如果值为 null。移除标签应使用remove(NamespacedKey)IllegalArgumentException- 如果没有找到适用于PersistentDataType.getPrimitiveType()的适配器
-
has
<P,C> boolean has(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<P, C> type) 返回持久元数据提供者是否注册了匹配所提供参数的元数据。此方法仅在找到的值与提供的键具有相同原始数据类型时才返回 true。
使用自定义
PersistentDataType实现存储值不会存储复杂数据类型。因此,存储 UUID(通过存储 byte[])将匹配 has("key",PersistentDataType.BYTE_ARRAY)。同样,存储的 byte[] 将始终匹配您的 UUIDPersistentDataType,即使它不是 16 字节长。此方法仅适用于自定义对象键。覆盖现有标签(如显示名称)将不起作用,因为值使用您的命名空间存储。
原文: Returns if the persistent metadata provider has metadata registered matching the provided parameters.
This method will only return true if the found value has the same primitive data type as the provided key.
Storing a value using a custom
PersistentDataTypeimplementation will not store the complex data type. Therefore storing a UUID (by storing a byte[]) will match has("key" ,PersistentDataType.BYTE_ARRAY). Likewise a stored byte[] will always match your UUIDPersistentDataTypeeven if it is not 16 bytes long.This method is only usable for custom object keys. Overwriting existing tags, like the display name, will not work as the values are stored using your namespace.
- 类型参数:
P- 存储的原始类型的通用类型C- 最终创建的复杂对象的通用类型- 参数:
key- 值存储在的键type- 原始存储值必须匹配的类型- 返回:
- 是否存在具有所提供键和类型的值
- 抛出:
IllegalArgumentException- 如果要查找的键为 nullIllegalArgumentException- 如果要转换找到的对象的类型为 null
-
has
返回持久元数据提供者是否注册了匹配所提供参数的元数据。此方法将返回 true,只要具有给定键的值存在,无论其类型如何。
此方法仅适用于自定义对象键。覆盖现有标签(如显示名称)将不起作用,因为值使用您的命名空间存储。
原文: Returns if the persistent metadata provider has metadata registered matching the provided parameters.
This method will return true as long as a value with the given key exists, regardless of its type.
This method is only usable for custom object keys. Overwriting existing tags, like the display name, will not work as the values are stored using your namespace.
- 参数:
key- 值存储在的键- 返回:
- 是否存在具有所提供键的值
- 抛出:
IllegalArgumentException- 如果要查找的键为 null
-
get
@Nullable <P,C> C get(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<P, C> type) 返回存储在PersistentDataHolder实例上的元数据值。原文: Returns the metadata value that is stored on the
PersistentDataHolderinstance.- 类型参数:
P- 存储的原始类型的通用类型C- 最终创建的复杂对象的通用类型- 参数:
key- 要在自定义标签映射中查找的键type- 值必须具有并将转换为的类型- 返回:
- 值,如果没有值映射到给定值下则返回
null - 抛出:
IllegalArgumentException- 如果要查找的键为 nullIllegalArgumentException- 如果要转换找到的对象的类型为 nullIllegalArgumentException- 如果在给定键下存在值,但无法使用给定类型访问IllegalArgumentException- 如果没有找到适用于PersistentDataType.getPrimitiveType()的适配器
-
getOrDefault
@NotNull <P,C> C getOrDefault(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<P, C> type, @NotNull C defaultValue) 返回存储在PersistentDataHolder实例上的元数据值。如果容器中不存在该值,则返回提供的默认值。原文: Returns the metadata value that is stored on the
PersistentDataHolderinstance. If the value does not exist in the container, the default value provided is returned.- 类型参数:
P- 存储的原始类型的通用类型C- 最终创建的复杂对象的通用类型- 参数:
key- 要在自定义标签映射中查找的键type- 值必须具有并将转换为的类型defaultValue- 如果没有找到所提供键的值,则返回的默认值- 返回:
- 值,或者如果没有值映射到给定键下则返回默认值
- 抛出:
IllegalArgumentException- 如果要查找的键为 nullIllegalArgumentException- 如果要转换找到的对象的类型为 nullIllegalArgumentException- 如果在给定键下存在值,但无法使用给定类型访问IllegalArgumentException- 如果没有找到适用于PersistentDataType.getPrimitiveType()的适配器
-
getKeys
获取此PersistentDataContainer实例上存在的键集。原文: Get the set of keys present on this
PersistentDataContainerinstance. Any changes made to the returned set will not be reflected on the instance.- 返回:
- 键集
-
remove
从PersistentDataHolder实例中移除自定义键。原文: Removes a custom key from the
PersistentDataHolderinstance.- 参数:
key- 要移除的键- 抛出:
IllegalArgumentException- 如果提供的键为 null
-
isEmpty
boolean isEmpty()返回容器实例是否为空,即其中没有条目。原文: Returns if the container instance is empty, therefore has no entries inside it.
- 返回:
- 布尔值
-
copyTo
将所有值从此PersistentDataContainer复制到提供的容器。此方法仅复制自定义对象键。现有标签(如显示名称)不会被复制,因为值使用您的命名空间存储。
原文: Copies all values from this
PersistentDataContainerto the provided container.This method only copies custom object keys. Existing tags, like the display name, will not be copied as the values are stored using your namespace.
- 参数:
other- 要复制到的容器replace- 是否替换目标容器中的任何匹配值- 抛出:
IllegalArgumentException- 如果另一个容器为 null
-
getAdapterContext
返回此标签容器使用的适配器上下文。原文: Returns the adapter context this tag container uses.
- 返回:
- 标签上下文
-