FlatFileStorageAPI supports the following variable types, ensuring compatibility with a wide range of data structures and types:
Basic Types:
- STRING
- UUID
- INTEGER
- DOUBLE
- FLOAT
- SHORT
- LONG
- BOOLEAN
- MATERIAL
Advanced Types:
Collections:
How to create a Var:
To create a new Var instance, use the following code:
final Var var = Var.getVar(instance, "path/path2");
This initializes a Var that is linked to the current instance ((instance) where the file will be) and the specified path ("path/path2"). Once created, this Var can be used to store and manage data with the supported variable types.
Methods Explanation:
setValue
This method is used to set the value of a specific variable, associating it with a given key and its corresponding type.
Example:
var.setValue(VarTypes.UUID,"key",UUID.randomUUID());
This sets a new UUID value for the key "key".
getValue
This method retrieves the value associated with the given key and type.
Example:
UUID value = var.getValue(VarTypes.UUID,"key");
note: u can also put an default value: var.getValue(VarTypes.UUID,"key",defaultValue);
This fetches the UUID value stored under the key "key".
save
This method saves the current state of the variable.
Example:
var.save();
This persists the variable’s value to disk or storage.
unload
This method unloads the variable, removing it from memory.
Example:
var.unload();
This ensures that the variable’s data is no longer in memory.
getKeys
This method retrieves all keys currently stored in the variable.
Example:
Set<String> keys = var.getKeys();
This fetches all keys from the variable.
saveAsync
This method saves the variable asynchronously, preventing server lag.
Example:
var.saveAsync();
This allows the save operation to happen in the background, improving server performance.