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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Called after all storages have been loaded, and variables have been redistributed if settings have changed.protected void
Clears the saveQueue of unsaved variables.void
close()
Called when Skript gets disabled.protected abstract boolean
connect()
(Re)connects to the database (not called on the first connect - do this inload_i(SectionNode)
).protected abstract void
Disconnects from the database.protected abstract File
protected @Nullable String
getValue(SectionNode n, String key)
protected <T> @Nullable T
getValue(SectionNode n, String key, Class<T> type)
boolean
load(SectionNode n)
protected abstract boolean
load_i(SectionNode n)
Loads variables stored here.protected abstract boolean
protected abstract boolean
Saves 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 settingclosed
to 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 thewriteThread
afterwards.- Parameters:
name
-type
-value
-- Returns:
- Whether the variable was saved
-