Class VariableStorage
java.lang.Object
io.github.syst3ms.skriptparser.variables.VariableStorage
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedBlockingQueue<SerializedVariable> protected booleanWhether this variable storage has beenclosed.protected final com.google.gson.Gsonprotected final StringThe name of the database used in the configurations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVariableStorage(SkriptLogger logger, @NotNull com.google.gson.Gson gson, @NotNull String name) Creates a new variable storage with the given names.protectedVariableStorage(SkriptLogger logger, @NotNull String name) Creates a new variable storage with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidCalled after all storages have been loaded, and variables have been redistributed if settings have changed.protected voidprotected Objectdeserialize(@NotNull String typeName, @NotNull com.google.gson.JsonElement value) getConfigurationValue(FileSection section, String key) Gets the string value at the given key of the given section node.protected <T> TgetConfigurationValue(FileSection section, String key, Class<T> classType) Gets the value at the given key of the given section node, parsed with the given class type.Gets the file needed for this variable storage from the given file name.protected abstract booleanload(Config.ConfigSection section) Loads configurations and should start loading variables too.final booleanloadConfiguration(Config.ConfigSection section) Loads the configuration for this variable storage from the given section node.protected voidloadVariable(String name, SerializedVariable variable) protected voidloadVariable(String name, @NotNull String type, @NotNull com.google.gson.JsonElement value) Loads a variable into Skript ram.protected abstract booleanChecks if this storage requires a file for storing data, like SQLite.protected abstract booleanSaves a variable.Creates aSerializedVariablefrom the given variable name and value.
-
Field Details
-
closed
protected volatile boolean closedWhether this variable storage has beenclosed. -
name
The name of the database used in the configurations. -
gson
protected final com.google.gson.Gson gson -
changesQueue
-
-
Constructor Details
-
VariableStorage
Creates a new variable storage with the given name. Gson will be handled.- Parameters:
logger- the logger to print logs to.name- the name.
-
VariableStorage
protected VariableStorage(SkriptLogger logger, @NotNull @NotNull com.google.gson.Gson gson, @NotNull @NotNull String name) Creates a new variable storage with the given names.- Parameters:
logger- the logger to print logs to.gson- the gson that controls the serialization of the json elements.name- the name.
-
-
Method Details
-
getConfigurationValue
Gets the string value at the given key of the given section node.- Parameters:
section- the file section.key- the key node.- Returns:
- the value, or
nullif the value was invalid, or not found.
-
getConfigurationValue
@Nullable protected <T> T getConfigurationValue(FileSection section, String key, Class<T> classType) Gets the value at the given key of the given section node, parsed with the given class type.- Type Parameters:
T- the class type generic.- Parameters:
section- the file section.key- the key node.classType- the class type.- Returns:
- the parsed value, or
nullif the value was invalid, or not found.
-
loadConfiguration
Loads the configuration for this variable storage from the given section node.- Parameters:
section- the section node.- Returns:
- whether the loading succeeded.
-
load
Loads configurations and should start loading variables too.- Returns:
- Whether the database could be loaded successfully, i.e. whether the configuration is correct and all variables could be loaded.
-
loadVariable
-
loadVariable
protected void loadVariable(String name, @NotNull @NotNull String type, @NotNull @NotNull com.google.gson.JsonElement value) Loads a variable into Skript ram. Call this insideload(ConfigSection)- Parameters:
name- the name of the variable.type- the type of the variable.value- the serialized value of the variable.
-
allLoaded
protected abstract void allLoaded()Called after all storages have been loaded, and variables have been redistributed if settings have changed. This should commit the first transaction. -
requiresFile
protected abstract boolean requiresFile()Checks if this storage requires a file for storing data, like SQLite.- Returns:
- if this storage needs a file.
-
getFile
-
serialize
Creates aSerializedVariablefrom the given variable name and value. Can be overriden to add custom encryption in your implemented VariableStorage. Call super.- Parameters:
name- the variable name.value- the variable value.- Returns:
- the serialized variable.
-
deserialize
protected Object deserialize(@NotNull @NotNull String typeName, @NotNull @NotNull com.google.gson.JsonElement value) Used byloadVariable(String, String, JsonElement). You don't need to use this method, but if you need to read the Object, this method allows for deserialization.- Parameters:
typeName- The name of the type.value- The value that represents a object.- Returns:
- The Object after deserialization, not present if not possible to deserialize due to missing serializer on Type.
-
clearChangesQueue
protected void clearChangesQueue() -
save
protected abstract boolean save(String name, @Nullable @Nullable String type, @Nullable @Nullable com.google.gson.JsonElement value) Saves a variable.typeandvalueare bothnullif this call is to delete the variable.- Parameters:
name- the name of the variable.type- the type of the variable.value- the serialized value of the variable.- Returns:
- Whether the variable was saved.
-