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(org.bukkit.event.Event event) Creates a copy of theVariablesMapfor local variables in an event.static voiddeleteVariable(String name, @Nullable org.bukkit.event.Event event, boolean local) Deletes a variable.static @UnmodifiableView List<VariablesStorage> static @Nullable ObjectgetVariable(String name, @Nullable org.bukkit.event.Event event, boolean local) Returns the internal value of the requested variable.getVariableIterator(String name, boolean local, @Nullable org.bukkit.event.Event event) Returns an iterator over the values of this list 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(org.bukkit.event.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(org.bukkit.event.Event event, @Nullable Object map) Sets local variables associated with given event.static voidsetVariable(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.static voidwithLocalVariables(org.bukkit.event.Event provider, org.bukkit.event.Event user, @NotNull Runnable action) Copies local variables from provider to user, runs action, then copies variables back to provider.
-
Field Details
-
Constructor Details
-
Variables
public Variables()
-
-
Method Details
-
getStores
- Returns:
- a copy of the list of variable storage handlers
-
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
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.
-
withLocalVariables
public static void withLocalVariables(org.bukkit.event.Event provider, org.bukkit.event.Event user, @NotNull @NotNull Runnable action) Copies local variables from provider to user, runs action, then copies variables back to provider. Removes local variables from user after action is finished.- Parameters:
provider- The originator of the local variables.user- The event to copy the variables to and back from.action- The code to run while the variables are copied.
-
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- 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.
-
getVariableIterator
public static Iterator<Pair<String,Object>> getVariableIterator(String name, boolean local, @Nullable @Nullable org.bukkit.event.Event event) Returns an iterator over the values of this list variable.- Parameters:
name- the variable's name. This must be the name of a list variable, ie. it must end in *.local- if this variable is a local or global variable.event- iflocalistrue, this is the event the local variable resides in.- Returns:
- an
IteratorofPairs, containing theStringindex andObjectvalue of the elements of the list. An empty iterator is returned if the variable does not exist.
-
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- 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 org.bukkit.event.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.
-