Config - TheDevTec/TheAPI GitHub Wiki
This class has a great variety of options. One option is to have custom comments on methods, another option is to store Config in different types of configurations - YAML, JSON, PROPERTIES or BYTE data
*Class automatically create file if missing.
Empty configuration without file
Config()
Configuration with path to file + optionable loading of file on class init
Config(String filePath) - Loading file automatically
Config(String filePath, boolean load)
Configuration with file - loading from file + optionable loading of file on class init
Config(File file) - Loading file automatically
Config(File file, boolean load)
Loading from String
Config config = ...
config.reload(String input);
Loading from File
Config config = ...
config.reload(File file);
DataTypes:
- YAML
- JSON
- PROPERTIES
- BYTE
Saving Config to the File
Config config = ...
config.save(File file); - Automatically save to DataType.YAML
config.save(File file, DataType dataType);
Saving Config to the String
Config config = ...
String result = config.toString(); - Automatically save to DataType.YAML
String result = config.toString(DataType dataType);
Changing File of Config
Config config = ...
config.setFile(File file);
Config config = ...
boolean exists = config.exists(String key);
Config config = ...
boolean exists = config.existsKey(String key);
Config config = ...
boolean json = config.isJson(String key);
@subKeys == Get subkeys under section subkeys? -> key.subkey.lower..
Config config = ...
Set<String set = config.getKeys();
Set<String set = config.getKeys(boolean subKeys);
@subKeys == Get subkeys under section subkeys? -> key.subkey.lower..
Config config = ...
Set<String set = config.getKeys(String section);
Set<String set = config.getKeys(String section, boolean subKeys);
Config config = ...
Object object = config.get(String key);
Config config = ...
T item = config.getAs(String key, Class<T> class);
@value == Saving object - Can be anything.. from ItemStack, custom class instance to List @comments == List of comments
Config config = ...
boolean absent = config.setIfAbsent(String key, Object value); - Without comments
boolean absent = config.setIfAbsent(String key, Object value, List<String> comments);
@value == Saving object - Can be anything.. from ItemStack, custom class instance to List
Config config = ...
config.set(String key, Object value);
Config config = ...
List<Object> list = config.getList(String key);
Config config = ...
List<String> list = config.getStringList(String key);
Config config = ...
List<T> list = config.getListAs(String key, Class<T> class);
Config config = new Config("plugins/TheAPI/myData.yml");
boolean absent = false;
absent = config.setIfAbsent("players.names", Arrays.asList("Straiker", "Houska"), Arrays.asList("# My cool comment"));
absent = config.setIfAbsent("players.uuids", Arrays.asList("some-uuid", "some-uuid")) ? true : (absent ? true : false);
absent = config.setIfAbsent("players", 2) ? true : (absent ? true : false);
if(absent) config.save();
int players = config.getInt("players");
List<String> names = config.getStringList("players.names");
List<String> uuids = config.getStringList("players.uuids");