Class PersistentDataUtils

java.lang.Object
ch.njol.skript.util.PersistentDataUtils

public class PersistentDataUtils extends Object
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
See Also:
SingleVariablePersistentDataType, ListVariablePersistentDataType, ExprRelationalVariable, CondHasRelationalVariable
  • Constructor Details

    • PersistentDataUtils

      public PersistentDataUtils()
  • Method Details

    • getNamespacedKey

      public static org.bukkit.NamespacedKey getNamespacedKey(String name)
      This returns a NamespacedKey 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

      public static Object[] getSingle(String name, Object... holders)
      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. See getConvertedHolders(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

      public static void setSingle(String name, Object value, Object... holders)
      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. See getConvertedHolders(Object[]) If this value is not serializable (see Classes.serialize(Object)), this value will be set under Metadata.
      See Also:
      getSingle(String, Object...), removeSingle(String, Object...)
    • removeSingle

      public 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. This method will check the holder's PersistentDataContainer and Metadata.
      Parameters:
      name - The name of the single variable (e.g. "myVariable" from {myVariable})
      holders - The holder(s) of the Persistent Data Tag. See getConvertedHolders(Object[])
      See Also:
      getSingle(String, Object...), setSingle(String, Object, Object...)
    • getList

      public static Object[] getList(String name, Object... holders)
      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. See getConvertedHolders(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

      public static void setList(String name, Object value, Object... holders)
      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. See getConvertedHolders(Object[]) If this value is not serializable (see Classes.serialize(Object)), this value will be set under Metadata.
      See Also:
      getList(String, Object...), removeSingle(String, Object...), setListMap(String, Map, Object)
    • removeList

      public static void removeList(String name, Object... holders)
      Removes the value of the Persistent Data Tag of the given name for the given holder(s). This method will check the holder's PersistentDataContainer and Metadata.
      Parameters:
      name - The name of the list variable (e.g. "myList::*" from {myList::*})
      holders - The holder(s) of the Persistent Data Tag. See getConvertedHolders(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

      public static @Nullable Map<String,​Object> getListMap(String name, Object holder)
      Returns the map of a list variable. Keyed by variable index. This method will check the holder's PersistentDataContainer and Metadata.
      Parameters:
      name - The full list variable (e.g. "myList::*" from {myList::*})
      holder - The holder of the Persistent Data Tag. See getConvertedHolders(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

      public static void setListMap(String name, Map<String,​Object> varMap, Object holder)
      Sets the list map of the given holder. This map should be gotten from getListMap(String, Object) This method will check the holder's PersistentDataContainer 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's PersistentDataContainer, this map will be set in their Metadata.
      holder - The holder of the Persistent Data Tag. See getConvertedHolders(Object[])
      See Also:
      setList(String, Object, Object...), getListMap(String, Object)
    • getListIndexes

      public static @Nullable Set<String> getListIndexes(String name, Object holder)
      This returns the indexes of a stored list. Mainly used for the ADD changer in ExprRelationalVariable
      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. See getConvertedHolders(Object[])
      Returns:
      The set of indexes, or an empty String set.
    • has

      public static boolean has(String name, Object... holders)
      Whether the given holders have a value under the given name. This method will check the holder's PersistentDataContainer and Metadata.
      Parameters:
      name - The name of the variable
      holders - The holder(s) of the Persistent Data Tag. See getConvertedHolders(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.