Package ch.njol.skript.util
Class PersistentDataUtils
java.lang.Object
ch.njol.skript.util.PersistentDataUtils
This class allows Persistent Data to work properly with Skript.
In Skript, Persistent Data is formatted like variables.
This looks like: set persistent data {isAdmin} of player to true
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object[]
Gets the Persistent Data Tag's value of the given list variable name from the given holder(s).getListIndexes(String name, Object holder)
This returns the indexes of a stored list.getListMap(String name, Object holder)
Returns the map of a list variable.static org.bukkit.NamespacedKey
getNamespacedKey(String name)
This returns aNamespacedKey
from the provided name with Skript as the namespace being used.static Object[]
Gets the Persistent Data Tag's value of the given single variable name from the given holder.static boolean
Whether the given holders have a value under the given name.static void
removeList(String name, Object... holders)
Removes the value of the Persistent Data Tag of the given name for the given holder(s).static void
removeSingle(String name, Object... holders)
Removes the Persistent Data Tag's value for the given holder(s) from the given name and value.static void
Sets the Persistent Data Tag's value for the given holder(s) from the given list variable name and value.static void
Sets the list map of the given holder.static void
Sets the Persistent Data Tag from the given name and value for the given holder.
-
Constructor Details
-
PersistentDataUtils
public PersistentDataUtils()
-
-
Method Details
-
getNamespacedKey
This returns aNamespacedKey
from the provided name with Skript as the namespace being used. The name will be encoded in Base64 to make sure the key name is valid.- Parameters:
name
- The name to convert- Returns:
- The created
NamespacedKey
-
getSingle
Gets the Persistent Data Tag's value of the given single variable name from the given holder. If the value set was not serializable, it was set under Metadata and is retrieved from Metadata here.- Parameters:
name
- The name of the single variable (e.g. "myVariable" from {myVariable})holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
- Returns:
- The Persistent Data Tag's value from each holder, or an empty list if no values could be retrieved.
- See Also:
setSingle(String, Object, Object...)
,removeSingle(String, Object...)
-
setSingle
Sets the Persistent Data Tag from the given name and value for the given holder.- Parameters:
name
- The name of the single variable (e.g. "myVariable" from {myVariable})value
- The value for the Persistent Data Tag to be set to.holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
If this value is not serializable (seeClasses.serialize(Object)
), this value will be set under Metadata.- See Also:
getSingle(String, Object...)
,removeSingle(String, Object...)
-
removeSingle
Removes the Persistent Data Tag's value for the given holder(s) from the given name and value. This method will check the holder'sPersistentDataContainer
and Metadata.- Parameters:
name
- The name of the single variable (e.g. "myVariable" from {myVariable})holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
- See Also:
getSingle(String, Object...)
,setSingle(String, Object, Object...)
-
getList
Gets the Persistent Data Tag's value of the given list variable name from the given holder(s). This method may return a single value, or multiple, depending on the given name. If the value set was not serializable, it was set under Metadata and is retrieved from Metadata here.- Parameters:
name
- The name of the list variable (e.g. "myList::*" from {myList::*})holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
- Returns:
- The Persistent Data Tag's value(s) from the holder, or an empty array if: the holder was invalid, the name was invalid, the key was invalid, or if no value(s) could be found.
- See Also:
setList(String, Object, Object...)
,removeList(String, Object...)
,getListMap(String, Object)
-
setList
Sets the Persistent Data Tag's value for the given holder(s) from the given list variable name and value.- Parameters:
name
- The name of the list variable (e.g. "myList::*" from {myList::*}) If the index of the name is "*", then the index set in the list will be "1". To set a different index, format the list variable like normal (e.g. "myList::index" from {myList::index})value
- The value for the Persistent Data Tag to be set to.holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
If this value is not serializable (seeClasses.serialize(Object)
), this value will be set under Metadata.- See Also:
getList(String, Object...)
,removeSingle(String, Object...)
,setListMap(String, Map, Object)
-
removeList
Removes the value of the Persistent Data Tag of the given name for the given holder(s). This method will check the holder'sPersistentDataContainer
and Metadata.- Parameters:
name
- The name of the list variable (e.g. "myList::*" from {myList::*})holders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
If the index of the name is "*", then the entire list will be cleared. To remove a specific index, format the list variable like normal (e.g. "myList::index" from {myList::index})- See Also:
getList(String, Object...)
,setList(String, Object, Object...)
-
getListMap
Returns the map of a list variable. Keyed by variable index. This method will check the holder'sPersistentDataContainer
and Metadata.- Parameters:
name
- The full list variable (e.g. "myList::*" from {myList::*})holder
- The holder of the Persistent Data Tag. SeegetConvertedHolders(Object[])
If it is not provided in this format, a null value will be returned.- Returns:
- The map of a list variable, or null if: If name was provided in an incorrect format, the holder is invalid, or if no value is set under that name for the holder.
- See Also:
getList(String, Object...)
,setListMap(String, Map, Object)
-
setListMap
Sets the list map of the given holder. This map should be gotten fromgetListMap(String, Object)
This method will check the holder'sPersistentDataContainer
and Metadata.- Parameters:
name
- The full list variable (e.g. "myList::*" from {myList::*}) If it is not provided in this format, nothing will be set.varMap
- The new map for Persistent Data Tag of the given holder. If a variable map doesn't already exist in the holder'sPersistentDataContainer
, this map will be set in their Metadata.holder
- The holder of the Persistent Data Tag. SeegetConvertedHolders(Object[])
- See Also:
setList(String, Object, Object...)
,getListMap(String, Object)
-
getListIndexes
This returns the indexes of a stored list. Mainly used for the ADD changer inExprRelationalVariable
- Parameters:
name
- The full list variable (e.g. "myList::*" from {myList::*}) If it is not provided in this format, nothing will be set.holder
- The holder of the Persistent Data Tag. SeegetConvertedHolders(Object[])
- Returns:
- The set of indexes, or an empty String set.
-
has
Whether the given holders have a value under the given name. This method will check the holder'sPersistentDataContainer
and Metadata.- Parameters:
name
- The name of the variableholders
- The holder(s) of the Persistent Data Tag. SeegetConvertedHolders(Object[])
(e.g. "myVariable" from {myVariable} OR "myList::index" from {myList::index} OR "myList::*" from {myList::*})- Returns:
- True if the user has something under the Persistent Data Tag from the given name. This method will return false if: the holder is invalid, the name is invalid, or if no value could be found.
-