-
Notifications
You must be signed in to change notification settings - Fork 25
Usage
First I'm going to show you the basic stuff:
Yaml yaml = new Yaml(NAME, PATH);
//or
Json json = new Json(NAME, PATH);
Creates a new Yaml/Json.
If the file or path doesn't exist it will be created for you (one of the in my opinion greatest features). Now you can set values to this file.
If the file already exists the file will just be loaded.
The Path can be nulled or set empty ("") so that the file will be created in the current directory. You mustn't use .yml or .json in your file name. LightningStorage handles file extensions automatically!
yaml.set(String key,Object value);
//or
json.set(String key)
//Example:
json.set("banana", true);
yaml.set("UseChatFilter", true);
This is a basic example of how to set values with LightningStorage, as you can see it is just like you know it from bukkit. As I've already mentioned, LightningStorage supports nested objects natively:
This:
yaml.set("ChatFilter.filterLevel", 3)
yaml.set("ChatFilter.use", true)
will produce the following yaml-file:
ChatFilter:
use: true
filterlevel: 3
And this:
json.set("ChatFilter.filterLevel", 3)
json.set("ChatFilter.use", true)
will produce the following json-file:
{
"ChatFilter": {
"filterlevel": 3,
"use": true
}
}
These methods are pretty much like self-explaining if you know bukkit: It is helpful to know that the methods are returning the standard value of the datatype if the file(json/yaml) doesn't contain them. This means if I try to get a boolean by the key "test" with the Methods getBoolean and the file doesn't contain the object it will return false. If I try to get a String that doesn't exist it will return null etc.
getBoolean(String key);
getByte(String key);
getInt(String key);
getFloat(String key);
getDouble(String key);
getLong(String key);
getString(String key);
getList(String key);
getStringList(String key);
getByteList(String key);
getIntegerList(String key);
getLongList(String key);
getMap(String key);
getString(String key)
### Nice & advanced stuff:
These methods will be boosting your productivity enormously. (More added soon.)
setDefault(String key, Object value);
will set a value only if it doesn't already exist, that is extremely helpful if you want to store player data or something like that in your file as we will see in the real world examples.
yaml.getFilePath();
Returns the absolute filepath of our file, this is very helpful if You are using multiple factory classes and don't want to declare an own file variable for every file.
yaml.getFile():
This returns the java.io file of the yaml/json if you want to use the methods of java.io for your file, to modify it in any way (coping, etc), without using the Yaml/Json - class this might be quite helpful.
2020-2022 - SimplixSoftworks