Package ch.njol.skript.variables
Class VariablesStorage
java.lang.Object
ch.njol.skript.variables.VariablesStorage
- All Implemented Interfaces:
Closeable
- Direct Known Subclasses:
DatabaseStorage,FlatFileStorage
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidCalled after all storages have been loaded, and variables have been redistributed if settings have changed.protected voidClears the saveQueue of unsaved variables.voidclose()Called when Skript gets disabled.protected abstract booleanconnect()(Re)connects to the database (not called on the first connect - do this inload_i(SectionNode)).protected abstract voidDisconnects from the database.protected abstract Fileprotected @Nullable StringgetValue(SectionNode n, String key)protected <T> @Nullable TgetValue(SectionNode n, String key, Class<T> type)booleanload(SectionNode n)protected abstract booleanload_i(SectionNode n)Loads variables stored here.protected abstract booleanprotected abstract booleanSaves a variable.void
-
Field Details
-
closed
protected volatile boolean closed -
databaseName
-
file
-
connectionLock
Must be locked afterVariables.getReadLock()(if that lock is used at all) -
backupTask
-
-
Constructor Details
-
VariablesStorage
-
-
Method Details
-
getValue
-
getValue
-
load
-
load_i
Loads variables stored here.- Returns:
- Whether the database could be loaded successfully, i.e. whether the config is correct and all variables could be loaded
-
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 (which is not empty if variables have been moved from another database to this one or vice versa), and start repeating transactions if applicable. -
requiresFile
protected abstract boolean requiresFile() -
getFile
-
connect
protected abstract boolean connect()(Re)connects to the database (not called on the first connect - do this inload_i(SectionNode)).- Returns:
- Whether the connection could be re-established. An error should be printed by this method prior to returning false.
-
disconnect
protected abstract void disconnect()Disconnects from the database. -
startBackupTask
-
close
public void close()Called when Skript gets disabled. The default implementation will wait for all variables to be saved before settingclosedto true and stopping the write thread, thus super.close() must be called if this method is overridden! -
clearChangesQueue
protected void clearChangesQueue()Clears the saveQueue of unsaved variables. Only used if all variables are saved immediately after calling this method. -
save
protected abstract boolean save(String name, @Nullable String type, @org.eclipse.jdt.annotation.Nullable byte[] value)Saves a variable. This is called from the main thread while variables are transferred between databases, and from thewriteThreadafterwards.- Parameters:
name-type-value-- Returns:
- Whether the variable was saved
-