mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-22 10:36:15 +01:00
Updated Storage (markdown)
parent
db2356ac61
commit
6eb5655092
20
Storage.md
20
Storage.md
@ -9,20 +9,20 @@ storageManager.defineDefaultStorageSystem(FileStorageSystem::new);
|
||||
```
|
||||
You can easily create your own by implementing the StorageSystem interface.
|
||||
|
||||
## Storage folder
|
||||
Storage folders are a way to separate your data in multiple categories. There are created/retrieved by calling:
|
||||
## Storage location
|
||||
Storage locations are a way to separate your data in multiple categories. There are created/retrieved by calling:
|
||||
```java
|
||||
StorageFolder storageFolder = storageManager.getFolder(YOUR_FOLDER_PATH);
|
||||
StorageLocation storageLocation = getLocation(YOUR_LOCATION_PATH);
|
||||
```
|
||||
You can then write/read anything from it as long as you know the key
|
||||
```java
|
||||
byte[] data;
|
||||
...
|
||||
storageFolder.set("test", data);
|
||||
data = storageFolder.get("test");
|
||||
storageLocation.set("test", data);
|
||||
data = storageLocation.get("test");
|
||||
```
|
||||
|
||||
WARNING: You shouldn't open a data folder using a different StorageSystem than the one it has been created with
|
||||
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](https://github.com/Minestom/Minestom/wiki/Data))
|
||||
@ -34,14 +34,14 @@ There are two kind of SerializableData that you would want to store:
|
||||
For the first type you would need:
|
||||
```java
|
||||
// The data is gonna be retrieved, cloned and applied to the DataContainer specified
|
||||
storageFolder.getAndCloneData(key, dataContainer);
|
||||
storageLocation.getAndCloneData(key, dataContainer);
|
||||
```
|
||||
And for the second:
|
||||
```java
|
||||
// The data is gonna be retrieved, applied to the DataContainer
|
||||
// And the storage folder will cache it for further saving
|
||||
storageFolder.getAndCacheData(key, dataContainer);
|
||||
// And the storage location will cache it for further saving
|
||||
storageLocation.getAndCacheData(key, dataContainer);
|
||||
...
|
||||
// Save all the cached SerializableData
|
||||
storageFolder.saveCachedData();
|
||||
storageLocation.saveCachedData();
|
||||
```
|
Loading…
Reference in New Issue
Block a user