Package ch.njol.skript.variables
Class FlatFileStorage
java.lang.Object
ch.njol.skript.variables.VariablesStorage
ch.njol.skript.variables.FlatFileStorage
- All Implemented Interfaces:
Closeable
TODO use a database (SQLite) instead and only load a limited amount of variables into RAM - e.g. 2 GB (configurable). If more variables are available they will be loaded when
accessed. (rem: print a warning when Skript starts)
rem: store null variables (in memory) to prevent looking up the same variables over and over again
-
Field Summary
Fields inherited from class ch.njol.skript.variables.VariablesStorage
backupTask, closed, connectionLock, databaseName, file
-
Constructor Summary
-
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 boolean
connect()
(Re)connects to the database (not called on the first connect - do this inVariablesStorage.load_i(SectionNode)
).protected void
Disconnects from the database.protected File
protected boolean
load_i(SectionNode n)
Doesn'ts lock the connection as required byVariables.variableLoaded(String, Object, VariablesStorage)
.protected boolean
protected boolean
Saves a variable.void
saveVariables(boolean finalSave)
Completely rewrites the while fileMethods inherited from class ch.njol.skript.variables.VariablesStorage
clearChangesQueue, getValue, getValue, load, startBackupTask
-
Field Details
-
UTF_8
-
-
Constructor Details
-
FlatFileStorage
-
-
Method Details
-
load_i
Doesn'ts lock the connection as required byVariables.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()- Specified by:
requiresFile
in classVariablesStorage
-
getFile
- Specified by:
getFile
in classVariablesStorage
-
save
protected boolean save(String name, @Nullable String type, @org.eclipse.jdt.annotation.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 theVariablesStorage.writeThread
afterwards.- Specified by:
save
in classVariablesStorage
- Returns:
- Whether the variable was saved
-
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 inVariablesStorage.load_i(SectionNode)
).- Specified by:
connect
in classVariablesStorage
- Returns:
- Whether the connection could be re-established. An error should be printed by this method prior to returning false.
-
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 settingVariablesStorage.closed
to true and stopping the write thread, thus super.close() must be called if this method is overridden!- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classVariablesStorage
-
saveVariables
public final void saveVariables(boolean finalSave)Completely rewrites the while file- Parameters:
finalSave
- whether this is the last save in this session or not.
-