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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
close()
Closes the variable systems: Process all changes left in thechangeQueue
. Stops thesaveThread
.static @Nullable Object
copyLocalVariables
(org.bukkit.event.Event event) Creates a copy of theVariablesMap
for local variables in an event.static void
deleteVariable
(String name, @Nullable org.bukkit.event.Event event, boolean local) Deletes a variable.static @Nullable Object
getVariable
(String name, @Nullable org.bukkit.event.Event event, boolean local) Returns the internal value of the requested variable.static boolean
load()
Load the variables configuration and all variables.static int
Gets 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.VariablesMap
removeLocals
(org.bukkit.event.Event event) Removes local variables associated with given event and returns them, if they exist.static @Nullable SerializedVariable.Value
Serializes the given value.static SerializedVariable
Creates aSerializedVariable
from the given variable name and value.static void
setLocalVariables
(org.bukkit.event.Event event, @Nullable Object map) Sets local variables associated with given event.static void
setVariable
(String name, @Nullable Object value, @Nullable org.bukkit.event.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
@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
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 theVariablesMap
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
- iflocal
istrue
, 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 aMap<String, Object>
for a list variable, ornull
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
- iflocal
istrue
, 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::*", butvalue
must benull
in this case.value
- The variable's value. Usenull
to delete the variable.event
- iflocal
istrue
, this is the event the local variable resides in.local
- if this variable is a local or global variable.
-
serialize
Creates aSerializedVariable
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
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.
-