Interface PersistentDataContainerView
- All Known Subinterfaces:
PersistentDataContainer
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
copyTo
(@NonNull PersistentDataContainer other, boolean replace) Copies all values from thisPersistentDataContainer
to the provided container.<P,
C> @Nullable C get
(@NonNull NamespacedKey key, @NonNull PersistentDataType<P, C> type) Returns the metadata value that is stored on thePersistentDataHolder
instance.@NonNull PersistentDataAdapterContext
Returns the adapter context this tag container uses.@NonNull Set
<NamespacedKey> getKeys()
Get the set of keys present on thisPersistentDataContainer
instance.<P,
C> @NonNull C getOrDefault
(@NonNull NamespacedKey key, @NonNull PersistentDataType<P, C> type, @NonNull C defaultValue) Returns the metadata value that is stored on thePersistentDataHolder
instance.boolean
has
(@NonNull NamespacedKey key) Returns if the persistent metadata provider has metadata registered matching the provided parameters.<P,
C> boolean has
(@NonNull NamespacedKey key, @NonNull PersistentDataType<P, C> 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.byte @NonNull []
Serialize thisPersistentDataContainer
instance to a byte array.
-
Method Details
-
has
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
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 UUIDPersistentDataType
even 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.
- Type Parameters:
P
- the generic type of the stored primitiveC
- the generic type of the eventually created complex object- Parameters:
key
- the key the value is stored undertype
- the type the primative stored value has to match- Returns:
- if a value with the provided key and type exists
- Throws:
IllegalArgumentException
- if the key to look up is nullIllegalArgumentException
- if the type to cast the found object to is null
-
has
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.
- Parameters:
key
- the key the value is stored under- Returns:
- if a value with the provided key exists
- Throws:
IllegalArgumentException
- if the key to look up is null
-
get
Returns the metadata value that is stored on thePersistentDataHolder
instance.- Type Parameters:
P
- the generic type of the stored primitiveC
- the generic type of the eventually created complex object- Parameters:
key
- the key to look up in the custom tag maptype
- the type the value must have and will be casted to- Returns:
- the value or
null
if no value was mapped under the given value - Throws:
IllegalArgumentException
- if the key to look up is nullIllegalArgumentException
- if the type to cast the found object to is nullIllegalArgumentException
- if a value exists under the given key, but cannot be accessed using the given typeIllegalArgumentException
- if no suitable adapter was found for thePersistentDataType.getPrimitiveType()
-
getOrDefault
<P,C> @NonNull C getOrDefault(@NonNull NamespacedKey key, @NonNull PersistentDataType<P, C> type, @NonNull C defaultValue) Returns the metadata value that is stored on thePersistentDataHolder
instance. If the value does not exist in the container, the default value provided is returned.- Type Parameters:
P
- the generic type of the stored primitiveC
- the generic type of the eventually created complex object- Parameters:
key
- 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 key- Returns:
- the value or the default value if no value was mapped under the given key
- Throws:
IllegalArgumentException
- if the key to look up is nullIllegalArgumentException
- if the type to cast the found object to is nullIllegalArgumentException
- if a value exists under the given key, but cannot be accessed using the given typeIllegalArgumentException
- if no suitable adapter was found for thePersistentDataType.getPrimitiveType()
-
getKeys
@NonNull Set<NamespacedKey> getKeys()Get the set of keys present on thisPersistentDataContainer
instance. Any changes made to the returned set will not be reflected on the instance.- Returns:
- the key set
-
isEmpty
boolean isEmpty()Returns if the container instance is empty, therefore has no entries inside it.- Returns:
- the boolean
-
copyTo
Copies all values from thisPersistentDataContainer
to 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.
- Parameters:
other
- the container to copy toreplace
- whether to replace any matching values in the target container- Throws:
IllegalArgumentException
- if the other container is null
-
getAdapterContext
@NonNull PersistentDataAdapterContext getAdapterContext()Returns the adapter context this tag container uses.- Returns:
- the tag context
-
serializeToBytes
Serialize thisPersistentDataContainer
instance to a byte array.- Returns:
- a binary representation of this container
- Throws:
IOException
- if we fail to write this container to a byte array
-