Class DataContainerUtil

java.lang.Object
de.eldoria.eldoutilities.pdc.DataContainerUtil

public final class DataContainerUtil extends Object
Utilities to work with the PersistentDataContainer
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    booleanToByte(boolean aBoolean)
    Converts a boolean to a byte.
    static boolean
    Converts a byte to boolean.
    static <T, Z> Z
    compute(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> map)
    Gets the PersistentDataContainer from item meta, computes the value by calling compute(PersistentDataHolder, NamespacedKey, PersistentDataType, Function) and applies the meta afterward again.
    static <T, Z> Z
    compute(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<@Nullable Z,Z> map)
    Compute a value in a PersistentDataContainer based on the current value
    static <T, Z> Z
    compute(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<@Nullable Z,Z> map)
    Compute a value in a PersistentDataContainer based on the current value
    static <T, Z> Z
    computeIfAbsent(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Compute a value in a PersistentDataContainer if it is not set.
    static <T, Z> Z
    computeIfAbsent(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Compute a value in a PersistentDataContainer if it is not set.
    static <T, Z> Z
    computeIfAbsent(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Compute a value in a PersistentDataContainer if it is not set.
    static <T, Z> Z
    computeIfPresent(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
    Compute a value in a PersistentDataContainer if is set.
    static <T, Z> Z
    computeIfPresent(@Nullable org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
    Compute a value in a PersistentDataContainer if is set.
    static <T, Z> Z
    computeIfPresent(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
    Compute a value in a PersistentDataContainer if is set.
    static <T, Z> Optional<Z>
    get(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Get a value from a persistent data holder.
    static <T, Z> Optional<Z>
    get(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Get a value from a persistent data holder.
    static <T, Z> Optional<Z>
    get(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Get a value from a persistent data holder.
    static <T, Z> Z
    getOrDefault(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
    Get a value from a persistent data holder.
    static <T, Z> Z
    getOrDefault(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
    Get a value from a persistent data holder.
    static <T, Z> Z
    getOrDefault(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
    Get a value from a persistent data holder.
    static <T, Z> boolean
    hasKey(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Check if a key is present in the PersistentDataContainer.
    static <T, Z> boolean
    hasKey(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Check if a key is present in the PersistentDataContainer.
    static <T, Z> boolean
    hasKey(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Check if a key is present in the PersistentDataContainer.
    static <T, Z> void
    putValue(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Set a value in a PersistentDataContainer.
    static <T, Z> void
    putValue(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Set a value in a PersistentDataContainer.
    static <T, Z> void
    putValue(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Set a value in a PersistentDataContainer.
    static <T, Z> boolean
    remove(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Remove a key from the PersistentDataContainer if it is set.
    static <T, Z> boolean
    remove(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Remove a key from the PersistentDataContainer if it is set.
    static <T, Z> boolean
    remove(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
    Remove a key from the PersistentDataContainer if it is set.
    static <T, Z> void
    setIfAbsent(@Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Sets a value in a data container if it is absent.
    static <T, Z> void
    setIfAbsent(@Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Sets a value in a data container if it is absent.
    static <T, Z> void
    setIfAbsent(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
    Sets a value in a data container if it is absent.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setIfAbsent

      public static <T, Z> void setIfAbsent(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Sets a value in a data container if it is absent.
      Type Parameters:
      T - type of key
      Z - type of value
      Parameters:
      container - the PersistentDataContainer
      key - key to set
      type - type of key
      value - value of key
    • setIfAbsent

      public static <T, Z> void setIfAbsent(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Sets a value in a data container if it is absent.
      Type Parameters:
      T - type of key
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to set
      type - type of key
      value - value of key
    • setIfAbsent

      public static <T, Z> void setIfAbsent(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Sets a value in a data container if it is absent.
      Type Parameters:
      T - type of key
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to set
      type - type of key
      value - value of key
    • compute

      @Nullable public static <T, Z> Z compute(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<@Nullable Z,Z> map)
      Compute a value in a PersistentDataContainer based on the current value
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      map - map the current value to the new value. Current value is null if key is not set.
      Returns:
      the mapped value. can be null if mapping function returns null or holder is null
    • compute

      @Nullable public static <T, Z> Z compute(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<@Nullable Z,Z> map)
      Compute a value in a PersistentDataContainer based on the current value
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      map - map the current value to the new value. Current value is null if key is not set.
      Returns:
      the mapped value. can be null if mapping function returns null or holder is null
    • compute

      @Nullable public static <T, Z> Z compute(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> map)
      Gets the PersistentDataContainer from item meta, computes the value by calling compute(PersistentDataHolder, NamespacedKey, PersistentDataType, Function) and applies the meta afterward again.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - item stack to change. This causes the item meta to be reapplied after computation of the value.
      key - key to compute
      type - type of key
      map - map the current value to the new value. Current value is null if key is not set.
      Returns:
      the mapped value. can be null if mapping function returns null or holder is null
    • computeIfAbsent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfAbsent(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Compute a value in a PersistentDataContainer if it is not set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      value - value which should be set if the key is not present.
      Returns:
      the value associated with this key. can be null if holder is null.
    • computeIfAbsent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfAbsent(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Compute a value in a PersistentDataContainer if it is not set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      value - value which should be set if the key is not present.
      Returns:
      the value associated with this key. can be null if holder is null.
    • computeIfAbsent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfAbsent(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Compute a value in a PersistentDataContainer if it is not set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      value - value which should be set if the key is not present.
      Returns:
      the value associated with this key. can be null if holder is null.
    • computeIfPresent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfPresent(@Nullable @Nullable org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
      Compute a value in a PersistentDataContainer if is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - the PersistentDataContainer
      key - key to compute
      type - type of key
      mappingFunction - function to map the current value to the new value.
      Returns:
      the value associated with this key. can be null if holder is null.
    • computeIfPresent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfPresent(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
      Compute a value in a PersistentDataContainer if is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      mappingFunction - function to map the current value to the new value.
      Returns:
      the value associated with this key. can be null if holder is null.
    • computeIfPresent

      @Contract("null, _, _, _ -> null; !null, _, _, _, -> !null") @Nullable public static <T, Z> Z computeIfPresent(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Function<Z,Z> mappingFunction)
      Compute a value in a PersistentDataContainer if is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to compute
      type - type of key
      mappingFunction - function to map the current value to the new value.
      Returns:
      the value associated with this key. can be null if holder is null.
    • get

      public static <T, Z> Optional<Z> get(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      Returns:
      result wrapped in an optional if present.
    • get

      public static <T, Z> Optional<Z> get(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      Returns:
      result wrapped in an optional if present.
    • get

      public static <T, Z> Optional<Z> get(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      Returns:
      result wrapped in an optional if present.
    • getOrDefault

      public static <T, Z> Z getOrDefault(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      defaultValue - default value if key is absent
      Returns:
      result wrapped in an optional if present.
    • getOrDefault

      public static <T, Z> Z getOrDefault(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      defaultValue - default value if key is absent
      Returns:
      result wrapped in an optional if present.
    • getOrDefault

      public static <T, Z> Z getOrDefault(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z defaultValue)
      Get a value from a persistent data holder.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to get
      type - type of key
      defaultValue - default value if key is absent
      Returns:
      result wrapped in an optional if present.
    • putValue

      public static <T, Z> void putValue(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Set a value in a PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - the PersistentDataContainer
      key - key to set
      type - type of key
      value - value to set
    • putValue

      public static <T, Z> void putValue(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Set a value in a PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to set
      type - type of key
      value - value to set
    • putValue

      public static <T, Z> void putValue(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type, Z value)
      Set a value in a PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to set
      type - type of key
      value - value to set
    • hasKey

      public static <T, Z> boolean hasKey(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Check if a key is present in the PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key is set
    • hasKey

      public static <T, Z> boolean hasKey(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Check if a key is present in the PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key is set
    • hasKey

      public static <T, Z> boolean hasKey(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Check if a key is present in the PersistentDataContainer.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key is set
    • remove

      public static <T, Z> boolean remove(org.bukkit.persistence.PersistentDataContainer container, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Remove a key from the PersistentDataContainer if it is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      container - holder of the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key was present and removed.
    • remove

      public static <T, Z> boolean remove(@Nullable @Nullable org.bukkit.persistence.PersistentDataHolder holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Remove a key from the PersistentDataContainer if it is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key was present and removed.
    • remove

      public static <T, Z> boolean remove(@Nullable @Nullable org.bukkit.inventory.ItemStack holder, org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T,Z> type)
      Remove a key from the PersistentDataContainer if it is set.
      Type Parameters:
      T - type of value
      Z - type of value
      Parameters:
      holder - holder of the PersistentDataContainer
      key - key to check
      type - type of key
      Returns:
      true if the key was present and removed.
    • byteToBoolean

      public static boolean byteToBoolean(Byte aByte)
      Converts a byte to boolean.
      Parameters:
      aByte - byte to convert
      Returns:
      byte as boolean. false if null
    • booleanToByte

      public static byte booleanToByte(boolean aBoolean)
      Converts a boolean to a byte.
      Parameters:
      aBoolean - boolean to convert
      Returns:
      boolean as byte.