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

Creating/Loading of config from file

*Class automatically create file if missing.

Constructors of class:

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)

Manual loading of Config from String/File

Loading from String

Config config = ...
config.reload(String input);

Loading from File

Config config = ...
config.reload(File file);

Saving of Config

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);

Asking

Exists key path in the Config

Config config = ...
boolean exists = config.exists(String key);

Exists section key in the Config (With value)

Config config = ...
boolean exists = config.existsKey(String key);

Is result Json

Config config = ...
boolean json = config.isJson(String key);

Getting and setting of values to the keys

Getting of keys

@subKeys == Get subkeys under section subkeys? -> key.subkey.lower..

Config config = ...
Set<String set = config.getKeys();

Set<String set = config.getKeys(boolean subKeys);

Getting of keys under specific section

@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);

Getting of Object

Config config = ...
Object object = config.get(String key);

Getting of specific type Object

Config config = ...
T item = config.getAs(String key, Class<T> class);

Setting of object if key absent in the config

@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);

Getting of List

Config config = ...
List<Object> list = config.getList(String key);

Getting of List

Config config = ...
List<String> list = config.getStringList(String key);

Getting of specific type List

Config config = ...
List<T> list = config.getListAs(String key, Class<T> class);

Examples

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");
⚠️ **GitHub.com Fallback** ⚠️