Class Variables

java.lang.Object
ch.njol.skript.variables.Variables

public class Variables extends Object
Handles all things related to variables.
See Also:
  • Field Details

    • YGGDRASIL_VERSION

      public static final short YGGDRASIL_VERSION
      The version of Yggdrasil this class is using.
      See Also:
    • yggdrasil

      public static final Yggdrasil yggdrasil
      The Yggdrasil instance used for (de)serialization.
    • caseInsensitiveVariables

      public static boolean caseInsensitiveVariables
      Whether variable names are case-sensitive.
  • Constructor Details

    • Variables

      public Variables()
  • Method Details

    • registerStorage

      public static <T extends VariablesStorage> boolean registerStorage(Class<T> storage, String... names)
      Register a VariableStorage class for Skript to create if the user config value matches.
      Type Parameters:
      T - A class to extend VariableStorage.
      Parameters:
      storage - The class of the VariableStorage implementation.
      names - The names used in the config of Skript to select this VariableStorage.
      Returns:
      if the operation was successful, or if it's already registered.
    • load

      public static boolean load()
      Load the variables configuration and all variables.

      May only be called once, when Skript is loading.

      Returns:
      whether the loading was successful.
    • splitVariableName

      public static String[] splitVariableName(String name)
      Splits the given variable name into its parts, separated by Variable.SEPARATOR.
      Parameters:
      name - the variable name.
      Returns:
      the parts.
    • removeLocals

      @Nullable public static @Nullable ch.njol.skript.variables.VariablesMap removeLocals(org.bukkit.event.Event event)
      Removes local variables associated with given event and returns them, if they exist.
      Parameters:
      event - the event.
      Returns:
      the local variables from the event, or null if the event had no local variables.
    • setLocalVariables

      public static void setLocalVariables(org.bukkit.event.Event event, @Nullable @Nullable Object map)
      Sets local variables associated with given event.

      If the given map is null, local variables for this event will be removed.

      Warning: this can overwrite local variables!

      Parameters:
      event - the event.
      map - the new local variables.
    • copyLocalVariables

      @Nullable public static @Nullable Object copyLocalVariables(org.bukkit.event.Event event)
      Creates a copy of the VariablesMap for local variables in an event.
      Parameters:
      event - the event to copy local variables from.
      Returns:
      the copy.
    • getVariable

      @Nullable public static @Nullable Object getVariable(String name, @Nullable @Nullable org.bukkit.event.Event event, boolean local)
      Returns the internal value of the requested variable.

      Do not modify the returned value!

      This does not take into consideration default variables. You must use get methods from Variable

      Parameters:
      name - the variable's name.
      event - if local is true, this is the event the local variable resides in.
      local - if this variable is a local or global variable.
      Returns:
      an Object for a normal variable or a Map<String, Object> for a list variable, or null if the variable is not set.
    • deleteVariable

      public static void deleteVariable(String name, @Nullable @Nullable org.bukkit.event.Event event, boolean local)
      Deletes a variable.
      Parameters:
      name - the variable's name.
      event - if local is true, this is the event the local variable resides in.
      local - if this variable is a local or global variable.
    • setVariable

      public static void setVariable(String name, @Nullable @Nullable Object value, @Nullable @Nullable org.bukkit.event.Event event, boolean local)
      Sets a variable.
      Parameters:
      name - the variable's name. Can be a "list variable::*", but value must be null in this case.
      value - The variable's value. Use null to delete the variable.
      event - if local is true, this is the event the local variable resides in.
      local - if this variable is a local or global variable.
    • serialize

      public static SerializedVariable serialize(String name, @Nullable @Nullable Object value)
      Creates a SerializedVariable from the given variable name and value.

      Must be called from Bukkit's main thread.

      Parameters:
      name - the variable name.
      value - the value.
      Returns:
      the serialized variable.
    • serialize

      public static @Nullable SerializedVariable.Value serialize(@Nullable @Nullable Object value)
      Serializes the given value.

      Must be called from Bukkit's main thread.

      Parameters:
      value - the value to serialize.
      Returns:
      the serialized value.
    • close

      public static void close()
      Closes the variable systems:
      • Process all changes left in the changeQueue.
      • Stops the saveThread.
    • numVariables

      public static int numVariables()
      Gets the amount of variables currently on the server.
      Returns:
      the amount of variables.