Minestom wiki
Search…
Persistent data
The Tag API should be used instead. These features will be removed in a future release.
Minestom allows you to specify your own way of managing/creating/removing persistent data. The storage manager can be accessed as such:
1
StorageManager storageManager = MinecraftServer.getStorageManager();
Copied!
You can and should define the StorageSystem (it defines how data is accessed, can be by using your OS file system or an external database for example)
1
// FileStorageSystem is the default system and uses your OS files to store data
2
storageManager.defineDefaultStorageSystem(FileStorageSystem::new);
Copied!
You can easily create your own by implementing the StorageSystem interface.

Storage location

Storage locations are a way to separate your data in multiple categories. There are created/retrieved by calling:
1
StorageLocation storageLocation = storageManager.getLocation(YOUR_LOCATION_IDENTIFIER);
Copied!
Please note that the "location" is not related in any way to a folder or a file, it can be but this is dependent on the StorageSystem implementation you are using (the storage system "FileStorageSystem" that we took as an example above WILL use/create a folder with the exact same name as the location, but this will not always be the case for all)
You can then write/read anything from it as long as you know the key
1
byte[] data;
2
...
3
storageLocation.set("test", data);
4
data = storageLocation.get("test");
Copied!
WARNING: You shouldn't open a data location using a different StorageSystem than the one it has been created with

Integration with SerializableData

Most of the data that you will store will be in the form of SerializableData. (see data)
There are two kinds of SerializableData that you would want to store:
  1. 1.
    Data which should not change but be unique and applied to multiple objects
  2. 2.
    Data linked to an element (or shared to multiple) and which should be synchronized
For the first type you would need:
1
// The data is gonna be retrieved, cloned and applied to the DataContainer specified
2
storageLocation.getAndCloneData(key, dataContainer);
Copied!
And for the second:
1
// The data is gonna be retrieved, applied to the DataContainer
2
// And the storage location will cache it for further saving
3
storageLocation.getAndCacheData(key, dataContainer);
4
...
5
// Save all the cached SerializableData
6
storageLocation.saveCachedData();
Copied!
Last modified 29d ago