Interface PersistentDataContainer


  • public interface PersistentDataContainer
    This interface represents a map like object, capable of storing custom tags in it.
    • Method Detail

      • has

        <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.

        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.

        Type Parameters:
        T - the generic type of the stored primitive
        Z - the generic type of the eventually created complex object
        Parameters:
        key - the key the value is stored under
        type - the type which primitive storage type has to match the value
        Returns:
        if a value
        Throws:
        NullPointerException - if the key to look up is null
        NullPointerException - if the type to cast the found object to is null
      • getOrDefault

        @NotNull
        <T,​Z> Z getOrDefault​(@NotNull
                                   NamespacedKey key,
                                   @NotNull
                                   PersistentDataType<T,​Z> type,
                                   @NotNull
                                   Z defaultValue)
        Returns the metadata value that is stored on the PersistentDataHolder instance. If the value does not exist in the container, the default value provided is returned.
        Type Parameters:
        T - the generic type of the stored primitive
        Z - the generic type of the eventually created complex object
        Parameters:
        key - the key to look up in the custom tag map
        type - the type the value must have and will be casted to
        defaultValue - 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 value
        Throws:
        NullPointerException - if the key to look up is null
        NullPointerException - if the type to cast the found object to is null
        IllegalArgumentException - if the value exists under the given key, but cannot be access using the given type
        IllegalArgumentException - if no suitable adapter will be found for the PersistentDataType.getPrimitiveType()
      • isEmpty

        boolean isEmpty()
        Returns if the container instance is empty, therefore has no entries inside it.
        Returns:
        the boolean
      • getAdapterContext

        @NotNull
        PersistentDataAdapterContext getAdapterContext()
        Returns the adapter context this tag container uses.
        Returns:
        the tag context