Repository navigation
Data Storage
nahkd123 edited this page Jul 28, 2021
·
1 revision
FeatherPowders provides drivers for other plugins to access with standard interace, including Data Storage API.
You can get the driver by using DataDriver.getDefaultDriver() from featherpowders.data package:
DataDriver driver = DataDriver.getDefaultDriver();DataDriver provide some methods for you:
-
getDriverName(): Returns the driver name (which allow user to choose default driver from configuration file) -
getContainerFor(Plugin): Get the data storage container for plugin
Here is the example code:
System.out.println("Now using " + driver.getDriverName() + " storage driver");
DataContainer container = driver.getContainerFor(myPluginInstance);Data Container is basically the container that stores all of your plugin data. That's why DataDriver.getContainerFor() asking for plugin as method argument.
There's only one method that you need, and that is getOrCreate(String):
DataStorage storage = contaier.getOrCreate("mystorage");This method will get the storage if it's already exists, or it just simply create new one
You now have DataStorage, which you can use it to store your data. There're some methods that you might want to use:
- General:
-
saveStorage(): Ask driver to save your data -
getParent(): Get parentDataStorage. It will gives younullif it's the root -
children(String): Get children storage
-
- Reading
-
exists(String): Check if the key exists inside storage -
get(String): Get object from storage -
get<Type>(String, Type): Get value from storage. The second argument is the default value
-
- Writing
-
set(String, Object): Write to storage. If the second argument is null, the value will be removed from storage
-