FlatFileStorageAPI is a lightweight and easy-to-use plugin designed for
Bukkit/Spigot/Paper Minecraft servers. It allows you to store persistent data in a
flatfile storage system.
The plugin supports
Java 8 to 21 and higher, as well as
Minecraft server versions from 1.14 to 1.21+.
Currently, the plugin supports many data types and is constantly evolving, with new advanced types being implemented, such as Bukkit classes (
ItemStack, Location).
All loaded data is stored in
RAM with
O(1) access speed because Java efficiently manages memory, such as in the case of a
HashMap holding
10,000,000 UUIDs, which typically requires around
160MB of memory (though overhead may increase total usage to
approximately 300MB).
Time(1M UUIDs):
- Set: 708ms (Due to the UUID.randomUUID() overhead, otherwise 128ms)
- Get: 128ms
- Save: 940ms
- Load: 822ms
You should organize your data into multiple files, each containing specific data types (e.g., PlayerData, Islands, etc.) to maximize loading and saving speed.
The plugin is in
beta stage(!) and continuously evolving. If you have any suggestions or improvements, feel free to let me know!
Supported Data Types:
- Types: String, UUID, Integer, BigInteger, Double, BigDecimal, Float, Short, Long, Boolean, Byte, Character, Material.
- Bukkit Types: Location, ItemStack, Inventory.
- Bukkit Representation Types: Chunk, World.
- Collections: List, Set, Array, Map
Using Var for Data Management
Installation & Setup
1. Download the API
Before using
Var, you need to download the API and include it in your project.
2. Add it to Your Project
- If using Maven, add the JAR to the /libs folder of your plugin project and declare it in your pom.xml:
Code (Java):
<dependency
>
<groupId
>your.
group.
id
</groupId
>
<artifactId
>FlatFileStorageAPI
</artifactId
>
<version
>
1.0
</version
>
<scope
>system
</scope
>
<systemPath
>$
{project.
basedir
}
/libs
/FlatFileStorageAPI.
jar
</systemPath
>
</dependency
>
- If using Gradle, add it as a local dependency.
Creating a Var Instance
To create a new
Var instance, use the following code:
Code (Java):
final Var var
= Var.
getVar
(instance,
"path/path2"
)
;
This initializes a
Var linked to the
current instance (instance, where the file will be stored) and the specified
path ("path/path2"). Once created, this
Var can store and manage data with supported variable types.
Methods & Usage
1. Setting a Value
Use setValue to store a value under a specific key with its associated type.
Example:
Code (Java):
var.
setValue
(VarTypes.
UUID,
"key", UUID.
randomUUID
(
)
)
;
This assigns a
UUID value to the key "key".
2. Retrieving a Value
Use getValue to retrieve a stored value based on its key and type.
Example:
Code (Java):
UUID value
= var.
getValue
(VarTypes.
UUID,
"key"
)
;
You can also specify a
default value in case the key is missing:
Code (Java):
UUID value
= var.
getValue
(VarTypes.
UUID,
"key", defaultValue
)
;
3. Saving Data
To save the current state of the
Var, use save().
Example:
Code (Java):
var.
save
(
)
;
This persists the stored data to
disk or storage.
Saving Asynchronously
For better server performance, use saveAsync() to save data in the background.
Example:
Code (Java):
var.
saveAsync
(
)
;
This prevents lag by handling the save operation
off the main thread.
4. Unloading Data from Memory
If you no longer need a
Var in memory, you can unload it using unload().
Example:
Code (Java):
var.
unload
(
)
;
This ensures that the
Var’s data is removed from
RAM, optimizing performance.
5. Retrieving All Stored Keys
Use getKeys() to get a list of all stored keys inside a
Var.
Example:
Code (Java):
Set
<String
> keys
= var.
getKeys
(
)
;
This allows you to check all available data stored in the
Var.
If you have any issues or suggestions, join our Discord:
https://discord.gg/veZJqU5wkT
![[IMG]](//proxy.spigotmc.org/adde9fcbc9b2b8b931164514e10818083ef58fa0/68747470733a2f2f6273746174732e6f72672f7369676e6174757265732f62756b6b69742f466c617446696c6553746f726167654150492e737667)