java.lang.Object
valorless.rarespawns.persistentdatacontainer.PDC

public class PDC extends Object
Convenience helpers for working with PersistentDataContainer (PDC) on ItemStacks and Entities.

Features:

  • Typed setters/getters for String, Integer, Double, Float, Boolean, UUID, and their List variants.
  • List values are serialized to JSON strings using JsonUtils for storage.
  • Booleans are stored as 0/1 INTEGER for version compatibility; getters also read BYTE if present.
  • Passing null to a Set method removes the key.
Keys are created relative to the calling plugin via Main.plugin.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PDC()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    Utility to convert a boolean to a BYTE value expected by some PDC uses.
    static Boolean
    GetBoolean(org.bukkit.entity.Entity entity, String key)
    Reads a boolean from an Entity.
    static Boolean
    GetBoolean(org.bukkit.inventory.ItemStack item, String key)
    Reads a boolean value.
    static Double
    GetDouble(org.bukkit.entity.Entity entity, String key)
    Retrieves a Double from an Entity.
    static Double
    GetDouble(org.bukkit.inventory.ItemStack item, String key)
    Retrieves a Double from an ItemStack.
    static List<Double>
    GetDoubleList(org.bukkit.entity.Entity entity, String key)
    Reads a List from JSON stored on an Entity.
    static List<Double>
    GetDoubleList(org.bukkit.inventory.ItemStack item, String key)
    Reads a List previously stored as JSON.
    static Float
    GetFloat(org.bukkit.entity.Entity entity, String key)
    Retrieves a Float from an Entity.
    static Float
    GetFloat(org.bukkit.inventory.ItemStack item, String key)
    Retrieves a Float from an ItemStack.
    static List<Float>
    GetFloatList(org.bukkit.entity.Entity entity, String key)
    Reads a List from JSON stored on an Entity.
    static List<Float>
    GetFloatList(org.bukkit.inventory.ItemStack item, String key)
    Reads a List previously stored as JSON.
    static Integer
    GetInteger(org.bukkit.entity.Entity entity, String key)
    Retrieves an Integer from an Entity.
    static Integer
    GetInteger(org.bukkit.inventory.ItemStack item, String key)
    Retrieves an Integer from an ItemStack.
    static List<Integer>
    GetIntegerList(org.bukkit.entity.Entity entity, String key)
    Reads a List from JSON stored on an Entity.
    static List<Integer>
    GetIntegerList(org.bukkit.inventory.ItemStack item, String key)
    Reads a List previously stored as JSON.
    static String
    GetString(org.bukkit.entity.Entity entity, String key)
    Retrieves a String from an Entity.
    static String
    GetString(org.bukkit.inventory.ItemStack item, String key)
    Retrieves a String value from an ItemStack.
    static List<String>
    GetStringList(org.bukkit.entity.Entity entity, String key)
    Reads a List from JSON stored on an Entity.
    static List<String>
    GetStringList(org.bukkit.inventory.ItemStack item, String key)
    Reads a List previously stored as JSON.
    static UUID
    GetUUID(org.bukkit.entity.Entity entity, String key)
    Reads a UUID previously stored as a String on an Entity.
    static UUID
    GetUUID(org.bukkit.inventory.ItemStack item, String key)
    Reads a UUID previously stored as a String.
    static Boolean
    Has(org.bukkit.entity.Entity entity, String key)
    Checks if an Entity has a value for the given key in its PDC.
    static Boolean
    Has(org.bukkit.inventory.ItemStack item, String key)
    Checks if an ItemStack has a value for the given key in its PDC.
    static Boolean
    Remove(org.bukkit.entity.Entity entity, String key)
    Removes a key from an Entity's PDC.
    static Boolean
    Remove(org.bukkit.inventory.ItemStack item, String key)
    Removes a key from an ItemStack's PDC.
    static void
    SetBoolean(org.bukkit.entity.Entity entity, String key, Boolean value)
    Stores a boolean value as INTEGER 0/1 on an Entity for compatibility.
    static void
    SetBoolean(org.bukkit.inventory.ItemStack item, String key, Boolean value)
    Stores a boolean value as INTEGER 0/1 for better version compatibility.
    static void
    SetDouble(org.bukkit.entity.Entity entity, String key, Double value)
    Stores a Double on an Entity.
    static void
    SetDouble(org.bukkit.inventory.ItemStack item, String key, Double value)
    Stores a Double on an ItemStack.
    static void
    SetDoubleList(org.bukkit.entity.Entity entity, String key, List<Double> value)
    Stores a List as JSON on an Entity.
    static void
    SetDoubleList(org.bukkit.inventory.ItemStack item, String key, List<Double> value)
    Stores a List as JSON.
    static void
    SetFloat(org.bukkit.entity.Entity entity, String key, Float value)
    Stores a Float on an Entity.
    static void
    SetFloat(org.bukkit.inventory.ItemStack item, String key, Float value)
    Stores a Float on an ItemStack.
    static void
    SetFloatList(org.bukkit.entity.Entity entity, String key, List<Float> value)
    Stores a List as JSON on an Entity.
    static void
    SetFloatList(org.bukkit.inventory.ItemStack item, String key, List<Float> value)
    Stores a List as JSON.
    static void
    SetInteger(org.bukkit.entity.Entity entity, String key, Integer value)
    Stores an Integer on an Entity.
    static void
    SetInteger(org.bukkit.inventory.ItemStack item, String key, Integer value)
    Stores an Integer on an ItemStack.
    static void
    SetIntegerList(org.bukkit.entity.Entity entity, String key, List<Integer> value)
    Stores a List as JSON on an Entity.
    static void
    SetIntegerList(org.bukkit.inventory.ItemStack item, String key, List<Integer> value)
    Stores a List as JSON.
    static void
    SetNamespacedKey(org.bukkit.entity.Entity entity, org.bukkit.NamespacedKey key, Object value, org.bukkit.persistence.PersistentDataType type)
    Sets a value using an explicit NamespacedKey and PersistentDataType on an Entity.
    static void
    SetNamespacedKey(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey key, Object value, org.bukkit.persistence.PersistentDataType type)
    Sets a value using an explicit NamespacedKey and PersistentDataType on an ItemStack.
    static void
    SetString(org.bukkit.entity.Entity entity, String key, String value)
    Stores a String on an Entity.
    static void
    SetString(org.bukkit.inventory.ItemStack item, String key, String value)
    Stores a String value on an ItemStack.
    static void
    SetStringList(org.bukkit.entity.Entity entity, String key, List<String> value)
    Stores a List as JSON on an Entity.
    static void
    SetStringList(org.bukkit.inventory.ItemStack item, String key, List<String> value)
    Stores a List by serializing it to JSON.
    static void
    SetUUID(org.bukkit.entity.Entity entity, String key, UUID uuid)
    Stores a UUID as a String on an Entity.
    static void
    SetUUID(org.bukkit.inventory.ItemStack item, String key, UUID uuid)
    Stores a UUID as a String.

    Methods inherited from class java.lang.Object

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

    • PDC

      public PDC()
  • Method Details

    • Has

      public static Boolean Has(org.bukkit.inventory.ItemStack item, String key)
      Checks if an ItemStack has a value for the given key in its PDC.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      true if present; false otherwise
    • Remove

      public static Boolean Remove(org.bukkit.inventory.ItemStack item, String key)
      Removes a key from an ItemStack's PDC.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      Returns:
      true on success; false if removal failed
    • SetNamespacedKey

      public static void SetNamespacedKey(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey key, Object value, org.bukkit.persistence.PersistentDataType type)
      Sets a value using an explicit NamespacedKey and PersistentDataType on an ItemStack.
      Parameters:
      item - the item to modify
      key - the explicit namespaced key
      value - the value to store
      type - the PDC data type for the value
    • SetString

      public static void SetString(org.bukkit.inventory.ItemStack item, String key, String value)
      Stores a String value on an ItemStack. If value is null, the key is removed.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the String to store, or null to remove
    • GetString

      public static String GetString(org.bukkit.inventory.ItemStack item, String key)
      Retrieves a String value from an ItemStack.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the stored String, or null if absent
    • SetStringList

      public static void SetStringList(org.bukkit.inventory.ItemStack item, String key, List<String> value)
      Stores a List by serializing it to JSON. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetStringList

      public static List<String> GetStringList(org.bukkit.inventory.ItemStack item, String key)
      Reads a List previously stored as JSON. Returns empty list if missing.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetInteger

      public static void SetInteger(org.bukkit.inventory.ItemStack item, String key, Integer value)
      Stores an Integer on an ItemStack. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the Integer to store, or null to remove
    • GetInteger

      public static Integer GetInteger(org.bukkit.inventory.ItemStack item, String key)
      Retrieves an Integer from an ItemStack.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Integer value, or null if absent
    • SetIntegerList

      public static void SetIntegerList(org.bukkit.inventory.ItemStack item, String key, List<Integer> value)
      Stores a List as JSON. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetIntegerList

      public static List<Integer> GetIntegerList(org.bukkit.inventory.ItemStack item, String key)
      Reads a List previously stored as JSON. Returns empty list if missing.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetDouble

      public static void SetDouble(org.bukkit.inventory.ItemStack item, String key, Double value)
      Stores a Double on an ItemStack. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the Double to store, or null to remove
    • GetDouble

      public static Double GetDouble(org.bukkit.inventory.ItemStack item, String key)
      Retrieves a Double from an ItemStack.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Double value, or null if absent
    • SetDoubleList

      public static void SetDoubleList(org.bukkit.inventory.ItemStack item, String key, List<Double> value)
      Stores a List as JSON. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetDoubleList

      public static List<Double> GetDoubleList(org.bukkit.inventory.ItemStack item, String key)
      Reads a List previously stored as JSON. Returns empty list if missing.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetFloat

      public static void SetFloat(org.bukkit.inventory.ItemStack item, String key, Float value)
      Stores a Float on an ItemStack. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the Float to store, or null to remove
    • GetFloat

      public static Float GetFloat(org.bukkit.inventory.ItemStack item, String key)
      Retrieves a Float from an ItemStack.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Float value, or null if absent
    • SetFloatList

      public static void SetFloatList(org.bukkit.inventory.ItemStack item, String key, List<Float> value)
      Stores a List as JSON. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetFloatList

      public static List<Float> GetFloatList(org.bukkit.inventory.ItemStack item, String key)
      Reads a List previously stored as JSON. Returns empty list if missing.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetBoolean

      public static void SetBoolean(org.bukkit.inventory.ItemStack item, String key, Boolean value)
      Stores a boolean value as INTEGER 0/1 for better version compatibility. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      value - the Boolean to store, or null to remove
    • GetBoolean

      public static Boolean GetBoolean(org.bukkit.inventory.ItemStack item, String key)
      Reads a boolean value. Prefers BYTE, falling back to INTEGER 0/1.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Boolean value, or null if absent
    • SetUUID

      public static void SetUUID(org.bukkit.inventory.ItemStack item, String key, UUID uuid)
      Stores a UUID as a String. Null removes the key.
      Parameters:
      item - the item to modify
      key - the key name (plugin-scoped)
      uuid - the UUID to store, or null to remove
    • GetUUID

      public static UUID GetUUID(org.bukkit.inventory.ItemStack item, String key)
      Reads a UUID previously stored as a String.
      Parameters:
      item - the item to inspect
      key - the key name (plugin-scoped)
      Returns:
      the UUID value, or null if absent/invalid
    • Has

      public static Boolean Has(org.bukkit.entity.Entity entity, String key)
      Checks if an Entity has a value for the given key in its PDC.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      true if present; false otherwise
    • Remove

      public static Boolean Remove(org.bukkit.entity.Entity entity, String key)
      Removes a key from an Entity's PDC.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      Returns:
      true on success; false if removal failed
    • SetNamespacedKey

      public static void SetNamespacedKey(org.bukkit.entity.Entity entity, org.bukkit.NamespacedKey key, Object value, org.bukkit.persistence.PersistentDataType type)
      Sets a value using an explicit NamespacedKey and PersistentDataType on an Entity.
      Parameters:
      entity - the entity to modify
      key - the explicit namespaced key
      value - the value to store
      type - the PDC data type for the value
    • SetString

      public static void SetString(org.bukkit.entity.Entity entity, String key, String value)
      Stores a String on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the String to store, or null to remove
    • GetString

      public static String GetString(org.bukkit.entity.Entity entity, String key)
      Retrieves a String from an Entity.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the stored String, or null if absent
    • SetStringList

      public static void SetStringList(org.bukkit.entity.Entity entity, String key, List<String> value)
      Stores a List as JSON on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetStringList

      public static List<String> GetStringList(org.bukkit.entity.Entity entity, String key)
      Reads a List from JSON stored on an Entity. Returns empty list if missing.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetInteger

      public static void SetInteger(org.bukkit.entity.Entity entity, String key, Integer value)
      Stores an Integer on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the Integer to store, or null to remove
    • GetInteger

      public static Integer GetInteger(org.bukkit.entity.Entity entity, String key)
      Retrieves an Integer from an Entity.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Integer value, or null if absent
    • SetIntegerList

      public static void SetIntegerList(org.bukkit.entity.Entity entity, String key, List<Integer> value)
      Stores a List as JSON on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetIntegerList

      public static List<Integer> GetIntegerList(org.bukkit.entity.Entity entity, String key)
      Reads a List from JSON stored on an Entity. Returns empty list if missing.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetDouble

      public static void SetDouble(org.bukkit.entity.Entity entity, String key, Double value)
      Stores a Double on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the Double to store, or null to remove
    • GetDouble

      public static Double GetDouble(org.bukkit.entity.Entity entity, String key)
      Retrieves a Double from an Entity.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Double value, or null if absent
    • SetDoubleList

      public static void SetDoubleList(org.bukkit.entity.Entity entity, String key, List<Double> value)
      Stores a List as JSON on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetDoubleList

      public static List<Double> GetDoubleList(org.bukkit.entity.Entity entity, String key)
      Reads a List from JSON stored on an Entity. Returns empty list if missing.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetFloat

      public static void SetFloat(org.bukkit.entity.Entity entity, String key, Float value)
      Stores a Float on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the Float to store, or null to remove
    • GetFloat

      public static Float GetFloat(org.bukkit.entity.Entity entity, String key)
      Retrieves a Float from an Entity.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Float value, or null if absent
    • SetFloatList

      public static void SetFloatList(org.bukkit.entity.Entity entity, String key, List<Float> value)
      Stores a List as JSON on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the list to store, or null to remove
    • GetFloatList

      public static List<Float> GetFloatList(org.bukkit.entity.Entity entity, String key)
      Reads a List from JSON stored on an Entity. Returns empty list if missing.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the list value, or empty list if absent
    • SetBoolean

      public static void SetBoolean(org.bukkit.entity.Entity entity, String key, Boolean value)
      Stores a boolean value as INTEGER 0/1 on an Entity for compatibility. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      value - the Boolean to store, or null to remove
    • GetBoolean

      public static Boolean GetBoolean(org.bukkit.entity.Entity entity, String key)
      Reads a boolean from an Entity. Tries BYTE, then falls back to INTEGER 0/1.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the Boolean value, or null if absent
    • SetUUID

      public static void SetUUID(org.bukkit.entity.Entity entity, String key, UUID uuid)
      Stores a UUID as a String on an Entity. Null removes the key.
      Parameters:
      entity - the entity to modify
      key - the key name (plugin-scoped)
      uuid - the UUID to store, or null to remove
    • GetUUID

      public static UUID GetUUID(org.bukkit.entity.Entity entity, String key)
      Reads a UUID previously stored as a String on an Entity.
      Parameters:
      entity - the entity to inspect
      key - the key name (plugin-scoped)
      Returns:
      the UUID value, or null if absent/invalid
    • ConvertBoolean

      public static byte ConvertBoolean(Boolean bool)
      Utility to convert a boolean to a BYTE value expected by some PDC uses.
      Parameters:
      bool - the boolean value
      Returns:
      1 if true; 0 if false