public interface PersistentDataContainer
Modifier and Type | Method and Description |
---|---|
<T,Z> Z |
get(@NotNull NamespacedKey key,
@NotNull PersistentDataType<T,Z> type)
Returns the metadata value that is stored on the
PersistentDataHolder instance. |
@NotNull PersistentDataAdapterContext |
getAdapterContext()
Returns the adapter context this tag container uses.
|
@NotNull Set<NamespacedKey> |
getKeys()
Get a set of keys present on this
PersistentDataContainer
instance. |
<T,Z> Z |
getOrDefault(@NotNull NamespacedKey key,
@NotNull PersistentDataType<T,Z> type,
Z defaultValue)
Returns the metadata value that is stored on the
PersistentDataHolder instance. |
<T,Z> boolean |
has(@NotNull NamespacedKey key,
@NotNull PersistentDataType<T,Z> type)
Returns if the persistent metadata provider has metadata registered
matching the provided parameters.
|
boolean |
isEmpty()
Returns if the container instance is empty, therefore has no entries
inside it.
|
void |
remove(@NotNull NamespacedKey key)
Removes a custom key from the
PersistentDataHolder instance. |
<T,Z> void |
set(@NotNull NamespacedKey key,
@NotNull PersistentDataType<T,Z> type,
Z value)
Stores a metadata value on the
PersistentDataHolder instance. |
<T,Z> void set(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<T,Z> type, @NotNull Z value)
PersistentDataHolder
instance.
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 PersistentDataHolder
may have stored under the provided
key.
T
- the generic java type of the tag valueZ
- the generic type of the object to storekey
- the key this value will be stored undertype
- the type this tag usesvalue
- the value stored in the tagNullPointerException
- if the key is nullNullPointerException
- if the type is nullNullPointerException
- if the value is null. Removing a tag should
be done using remove(NamespacedKey)
IllegalArgumentException
- if no suitable adapter will be found for
the PersistentDataType.getPrimitiveType()
<T,Z> boolean has(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<T,Z> type)
This method will only return if the found value has the same primitive data type as the provided key.
Storing a value using a custom PersistentDataType
implementation
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 UUID PersistentDataType
even if it is not 16
bytes long.
This method is only usable for custom object keys. Overwriting existing tags, like the the display name, will not work as the values are stored using your namespace.
T
- the generic type of the stored primitiveZ
- the generic type of the eventually created complex objectkey
- the key the value is stored undertype
- the type which primitive storage type has to match the valueNullPointerException
- if the key to look up is nullNullPointerException
- if the type to cast the found object to is
null@Nullable <T,Z> Z get(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<T,Z> type)
PersistentDataHolder
instance.T
- the generic type of the stored primitiveZ
- the generic type of the eventually created complex objectkey
- the key to look up in the custom tag maptype
- the type the value must have and will be casted tonull
if no value was mapped under the given
valueNullPointerException
- if the key to look up is nullNullPointerException
- if the type to cast the found object to is
nullIllegalArgumentException
- if the value exists under the given key,
but cannot be access using the given typeIllegalArgumentException
- if no suitable adapter will be found for
the PersistentDataType.getPrimitiveType()
@NotNull <T,Z> Z getOrDefault(@NotNull @NotNull NamespacedKey key, @NotNull @NotNull PersistentDataType<T,Z> type, @NotNull Z defaultValue)
PersistentDataHolder
instance. If the value does not exist in the
container, the default value provided is returned.T
- the generic type of the stored primitiveZ
- the generic type of the eventually created complex objectkey
- the key to look up in the custom tag maptype
- the type the value must have and will be casted todefaultValue
- the default value to return if no value was found for
the provided keyNullPointerException
- if the key to look up is nullNullPointerException
- if the type to cast the found object to is
nullIllegalArgumentException
- if the value exists under the given key,
but cannot be access using the given typeIllegalArgumentException
- if no suitable adapter will be found for
the PersistentDataType.getPrimitiveType()
@NotNull @NotNull Set<NamespacedKey> getKeys()
PersistentDataContainer
instance.
Any changes made to the returned set will not be reflected on the
instance.void remove(@NotNull @NotNull NamespacedKey key)
PersistentDataHolder
instance.key
- the keyNullPointerException
- if the provided key is nullboolean isEmpty()
@NotNull @NotNull PersistentDataAdapterContext getAdapterContext()
Copyright © 2021. All rights reserved.