Package ch.njol.skript.variables
Class Variables
java.lang.Object
ch.njol.skript.variables.Variables
Handles all things related to variables.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose()Closes the variable systems: Process all changes left in thechangeQueue. Stops thesaveThread.static @Nullable ObjectcopyLocalVariables(Event event) Creates a copy of theVariablesMapfor local variables in an event.static voiddeleteVariable(String name, @Nullable Event event, boolean local) Deletes a variable.static @Nullable ObjectgetVariable(String name, @Nullable Event event, boolean local) Returns the internal value of the requested variable.static booleanload()Load the variables configuration and all variables.static intGets the amount of variables currently on the server.static <T extends VariablesStorage>
booleanregisterStorage(Class<T> storage, String... names) Register a VariableStorage class for Skript to create if the user config value matches.static @Nullable ch.njol.skript.variables.VariablesMapremoveLocals(Event event) Removes local variables associated with given event and returns them, if they exist.static @Nullable SerializedVariable.ValueSerializes the given value.static SerializedVariableCreates aSerializedVariablefrom the given variable name and value.static voidsetLocalVariables(Event event, @Nullable Object map) Sets local variables associated with given event.static voidsetVariable(String name, @Nullable Object value, @Nullable Event event, boolean local) Sets a variable.static String[]splitVariableName(String name) Splits the given variable name into its parts, separated byVariable.SEPARATOR.
-
Field Details
-
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
Splits the given variable name into its parts, separated byVariable.SEPARATOR.- Parameters:
name- the variable name.- Returns:
- the parts.
-
removeLocals
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
nullif the event had no local variables.
-
setLocalVariables
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
Creates a copy of theVariablesMapfor 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 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- iflocalistrue, this is the event the local variable resides in.local- if this variable is a local or global variable.- Returns:
- an
Objectfor a normal variable or aMap<String, Object>for a list variable, ornullif the variable is not set.
-
deleteVariable
Deletes a variable.- Parameters:
name- the variable's name.event- iflocalistrue, 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 Event event, boolean local) Sets a variable.- Parameters:
name- the variable's name. Can be a "list variable::*", butvaluemust benullin this case.value- The variable's value. Usenullto delete the variable.event- iflocalistrue, this is the event the local variable resides in.local- if this variable is a local or global variable.
-
serialize
Creates aSerializedVariablefrom 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
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.
- Process all changes left in the
-
numVariables
public static int numVariables()Gets the amount of variables currently on the server.- Returns:
- the amount of variables.
-