Class FlatFileStorage
- All Implemented Interfaces:
Closeable
-
Field Summary
Fields inherited from class ch.njol.skript.variables.VariablesStorage
backupTask, closed, connectionLock, databaseName, file
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called after all storages have been loaded, and variables have been redistributed if settings have changed.void
close()
Called when Skript gets disabled.protected final boolean
connect()
(Re)connects to the database.protected final void
Disconnects from the database.protected File
Gets the file needed for this variable storage from the given file name.protected boolean
load_i
(SectionNode sectionNode) Loads the variables in the CSV file.protected boolean
Checks if this storage requires a file for storing its data.protected boolean
Saves a variable.final void
saveVariables
(boolean finalSave) Completely rewrites the CSV file.Methods inherited from class ch.njol.skript.variables.VariablesStorage
clearChangesQueue, getValue, getValue, load, startBackupTask
-
Field Details
-
FILE_CHARSET
TheCharset
used in the CSV storage file.
-
-
Method Details
-
load_i
Loads the variables in the CSV file.Doesn't lock the connection, as required by
Variables.variableLoaded(String, Object, VariablesStorage)
.- Specified by:
load_i
in classVariablesStorage
- Returns:
- Whether the database could be loaded successfully, i.e. whether the config is correct and all variables could be loaded.
-
allLoaded
protected void allLoaded()Description copied from class:VariablesStorage
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.- Specified by:
allLoaded
in classVariablesStorage
-
requiresFile
protected boolean requiresFile()Description copied from class:VariablesStorage
Checks if this storage requires a file for storing its data.- Specified by:
requiresFile
in classVariablesStorage
- Returns:
- if this storage needs a file.
-
getFile
Description copied from class:VariablesStorage
Gets the file needed for this variable storage from the given file name.Will only be called if
VariablesStorage.requiresFile()
istrue
.- Specified by:
getFile
in classVariablesStorage
- Parameters:
fileName
- the given file name.- Returns:
- the
File
object.
-
disconnect
protected final void disconnect()Description copied from class:VariablesStorage
Disconnects from the database.- Specified by:
disconnect
in classVariablesStorage
-
connect
protected final boolean connect()Description copied from class:VariablesStorage
(Re)connects to the database.Not called on the first connect: do this in
VariablesStorage.load_i(SectionNode)
. An error should be printed by this method prior to returningfalse
.- Specified by:
connect
in classVariablesStorage
- Returns:
- whether the connection could be re-established.
-
close
public void close()Description copied from class:VariablesStorage
Called when Skript gets disabled.The default implementation will wait for all variables to be saved before setting
VariablesStorage.closed
totrue
and stopping thewrite thread
.Therefore, make sure to call
super.close()
if this method is overridden.- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classVariablesStorage
-
save
protected boolean save(String name, @Nullable @Nullable String type, @Nullable @org.jetbrains.annotations.Nullable byte[] value) Description copied from class:VariablesStorage
Saves a variable.This is called from the main thread while variables are transferred between databases, and from the
VariablesStorage.writeThread
afterwards.type
andvalue
are bothnull
iff this call is to delete the variable.- Specified by:
save
in classVariablesStorage
- 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.
-
saveVariables
public final void saveVariables(boolean finalSave) Completely rewrites the CSV file.The
finalSave
argument is used to determine if thesave
andbackup
tasks should be cancelled, and if the storage should reconnect after saving.- Parameters:
finalSave
- whether this is the last save in this session or not.
-