mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-22 18:46:27 +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.
|
You can easily create your own by implementing the StorageSystem interface.
|
||||||
|
|
||||||
## Storage folder
|
## Storage location
|
||||||
Storage folders are a way to separate your data in multiple categories. There are created/retrieved by calling:
|
Storage locations are a way to separate your data in multiple categories. There are created/retrieved by calling:
|
||||||
```java
|
```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
|
You can then write/read anything from it as long as you know the key
|
||||||
```java
|
```java
|
||||||
byte[] data;
|
byte[] data;
|
||||||
...
|
...
|
||||||
storageFolder.set("test", data);
|
storageLocation.set("test", data);
|
||||||
data = storageFolder.get("test");
|
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
|
## 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))
|
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:
|
For the first type you would need:
|
||||||
```java
|
```java
|
||||||
// The data is gonna be retrieved, cloned and applied to the DataContainer specified
|
// 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:
|
And for the second:
|
||||||
```java
|
```java
|
||||||
// The data is gonna be retrieved, applied to the DataContainer
|
// The data is gonna be retrieved, applied to the DataContainer
|
||||||
// And the storage folder will cache it for further saving
|
// And the storage location will cache it for further saving
|
||||||
storageFolder.getAndCacheData(key, dataContainer);
|
storageLocation.getAndCacheData(key, dataContainer);
|
||||||
...
|
...
|
||||||
// Save all the cached SerializableData
|
// Save all the cached SerializableData
|
||||||
storageFolder.saveCachedData();
|
storageLocation.saveCachedData();
|
||||||
```
|
```
|
Loading…
Reference in New Issue
Block a user