Class PDC
java.lang.Object
valorless.rarespawns.persistentdatacontainer.PDC
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byteConvertBoolean(Boolean bool) Utility to convert a boolean to a BYTE value expected by some PDC uses.static BooleanGetBoolean(org.bukkit.entity.Entity entity, String key) Reads a boolean from an Entity.static BooleanGetBoolean(org.bukkit.inventory.ItemStack item, String key) Reads a boolean value.static DoubleRetrieves a Double from an Entity.static DoubleRetrieves a Double from an ItemStack.GetDoubleList(org.bukkit.entity.Entity entity, String key) Reads a Listfrom JSON stored on an Entity. GetDoubleList(org.bukkit.inventory.ItemStack item, String key) Reads a Listpreviously stored as JSON. static FloatRetrieves a Float from an Entity.static FloatRetrieves a Float from an ItemStack.GetFloatList(org.bukkit.entity.Entity entity, String key) Reads a Listfrom JSON stored on an Entity. GetFloatList(org.bukkit.inventory.ItemStack item, String key) Reads a Listpreviously stored as JSON. static IntegerGetInteger(org.bukkit.entity.Entity entity, String key) Retrieves an Integer from an Entity.static IntegerGetInteger(org.bukkit.inventory.ItemStack item, String key) Retrieves an Integer from an ItemStack.GetIntegerList(org.bukkit.entity.Entity entity, String key) Reads a Listfrom JSON stored on an Entity. GetIntegerList(org.bukkit.inventory.ItemStack item, String key) Reads a Listpreviously stored as JSON. static StringRetrieves a String from an Entity.static StringRetrieves a String value from an ItemStack.GetStringList(org.bukkit.entity.Entity entity, String key) Reads a Listfrom JSON stored on an Entity. GetStringList(org.bukkit.inventory.ItemStack item, String key) Reads a Listpreviously stored as JSON. static UUIDReads a UUID previously stored as a String on an Entity.static UUIDReads a UUID previously stored as a String.static BooleanChecks if an Entity has a value for the given key in its PDC.static BooleanChecks if an ItemStack has a value for the given key in its PDC.static BooleanRemoves a key from an Entity's PDC.static BooleanRemoves a key from an ItemStack's PDC.static voidSetBoolean(org.bukkit.entity.Entity entity, String key, Boolean value) Stores a boolean value as INTEGER 0/1 on an Entity for compatibility.static voidSetBoolean(org.bukkit.inventory.ItemStack item, String key, Boolean value) Stores a boolean value as INTEGER 0/1 for better version compatibility.static voidStores a Double on an Entity.static voidStores a Double on an ItemStack.static voidSetDoubleList(org.bukkit.entity.Entity entity, String key, List<Double> value) Stores a Listas JSON on an Entity. static voidSetDoubleList(org.bukkit.inventory.ItemStack item, String key, List<Double> value) Stores a Listas JSON. static voidStores a Float on an Entity.static voidStores a Float on an ItemStack.static voidSetFloatList(org.bukkit.entity.Entity entity, String key, List<Float> value) Stores a Listas JSON on an Entity. static voidSetFloatList(org.bukkit.inventory.ItemStack item, String key, List<Float> value) Stores a Listas JSON. static voidSetInteger(org.bukkit.entity.Entity entity, String key, Integer value) Stores an Integer on an Entity.static voidSetInteger(org.bukkit.inventory.ItemStack item, String key, Integer value) Stores an Integer on an ItemStack.static voidSetIntegerList(org.bukkit.entity.Entity entity, String key, List<Integer> value) Stores a Listas JSON on an Entity. static voidSetIntegerList(org.bukkit.inventory.ItemStack item, String key, List<Integer> value) Stores a Listas JSON. static voidSetNamespacedKey(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 voidSetNamespacedKey(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 voidStores a String on an Entity.static voidStores a String value on an ItemStack.static voidSetStringList(org.bukkit.entity.Entity entity, String key, List<String> value) Stores a Listas JSON on an Entity. static voidSetStringList(org.bukkit.inventory.ItemStack item, String key, List<String> value) Stores a Listby serializing it to JSON. static voidStores a UUID as a String on an Entity.static voidStores a UUID as a String.
-
Constructor Details
-
PDC
public PDC()
-
-
Method Details
-
Has
Checks if an ItemStack has a value for the given key in its PDC.- Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- true if present; false otherwise
-
Remove
Removes a key from an ItemStack's PDC.- Parameters:
item- the item to modifykey- 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 modifykey- the explicit namespaced keyvalue- the value to storetype- the PDC data type for the value
-
SetString
Stores a String value on an ItemStack. If value is null, the key is removed.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the String to store, or null to remove
-
GetString
Retrieves a String value from an ItemStack.- Parameters:
item- the item to inspectkey- 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 Listby serializing it to JSON. Null removes the key. - Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetStringList
Reads a Listpreviously stored as JSON. Returns empty list if missing. - Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetInteger
Stores an Integer on an ItemStack. Null removes the key.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the Integer to store, or null to remove
-
GetInteger
Retrieves an Integer from an ItemStack.- Parameters:
item- the item to inspectkey- 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 Listas JSON. Null removes the key. - Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetIntegerList
Reads a Listpreviously stored as JSON. Returns empty list if missing. - Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetDouble
Stores a Double on an ItemStack. Null removes the key.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the Double to store, or null to remove
-
GetDouble
Retrieves a Double from an ItemStack.- Parameters:
item- the item to inspectkey- 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 Listas JSON. Null removes the key. - Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetDoubleList
Reads a Listpreviously stored as JSON. Returns empty list if missing. - Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetFloat
Stores a Float on an ItemStack. Null removes the key.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the Float to store, or null to remove
-
GetFloat
Retrieves a Float from an ItemStack.- Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the Float value, or null if absent
-
SetFloatList
Stores a Listas JSON. Null removes the key. - Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetFloatList
Reads a Listpreviously stored as JSON. Returns empty list if missing. - Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetBoolean
Stores a boolean value as INTEGER 0/1 for better version compatibility. Null removes the key.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)value- the Boolean to store, or null to remove
-
GetBoolean
Reads a boolean value. Prefers BYTE, falling back to INTEGER 0/1.- Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the Boolean value, or null if absent
-
SetUUID
Stores a UUID as a String. Null removes the key.- Parameters:
item- the item to modifykey- the key name (plugin-scoped)uuid- the UUID to store, or null to remove
-
GetUUID
Reads a UUID previously stored as a String.- Parameters:
item- the item to inspectkey- the key name (plugin-scoped)- Returns:
- the UUID value, or null if absent/invalid
-
Has
Checks if an Entity has a value for the given key in its PDC.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- true if present; false otherwise
-
Remove
Removes a key from an Entity's PDC.- Parameters:
entity- the entity to modifykey- 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 modifykey- the explicit namespaced keyvalue- the value to storetype- the PDC data type for the value
-
SetString
Stores a String on an Entity. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the String to store, or null to remove
-
GetString
Retrieves a String from an Entity.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the stored String, or null if absent
-
SetStringList
Stores a Listas JSON on an Entity. Null removes the key. - Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetStringList
Reads a Listfrom JSON stored on an Entity. Returns empty list if missing. - Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetInteger
Stores an Integer on an Entity. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the Integer to store, or null to remove
-
GetInteger
Retrieves an Integer from an Entity.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the Integer value, or null if absent
-
SetIntegerList
Stores a Listas JSON on an Entity. Null removes the key. - Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetIntegerList
Reads a Listfrom JSON stored on an Entity. Returns empty list if missing. - Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetDouble
Stores a Double on an Entity. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the Double to store, or null to remove
-
GetDouble
Retrieves a Double from an Entity.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the Double value, or null if absent
-
SetDoubleList
Stores a Listas JSON on an Entity. Null removes the key. - Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetDoubleList
Reads a Listfrom JSON stored on an Entity. Returns empty list if missing. - Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetFloat
Stores a Float on an Entity. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the Float to store, or null to remove
-
GetFloat
Retrieves a Float from an Entity.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the Float value, or null if absent
-
SetFloatList
Stores a Listas JSON on an Entity. Null removes the key. - Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the list to store, or null to remove
-
GetFloatList
Reads a Listfrom JSON stored on an Entity. Returns empty list if missing. - Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the list value, or empty list if absent
-
SetBoolean
Stores a boolean value as INTEGER 0/1 on an Entity for compatibility. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)value- the Boolean to store, or null to remove
-
GetBoolean
Reads a boolean from an Entity. Tries BYTE, then falls back to INTEGER 0/1.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the Boolean value, or null if absent
-
SetUUID
Stores a UUID as a String on an Entity. Null removes the key.- Parameters:
entity- the entity to modifykey- the key name (plugin-scoped)uuid- the UUID to store, or null to remove
-
GetUUID
Reads a UUID previously stored as a String on an Entity.- Parameters:
entity- the entity to inspectkey- the key name (plugin-scoped)- Returns:
- the UUID value, or null if absent/invalid
-
ConvertBoolean
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
-