Skip to content

Developer Config

ludgart edited this page Jan 14, 2021 · 5 revisions

Developer Config

Creating configuration files is super easy with the API. Every config file have his own version for upgrading in future versions.
The version format must be "0.0.1".

Creating the config

Config CORE_CONFIG = new Config("core.yml", this.getPluginName());

Adding entries

// boolean
CORE_CONFIG.set("config.test.enabled", false, "0.0.1");

// String
CORE_CONFIG.set("config.test.name", "custom-name", "0.0.1");

// int
CORE_CONFIG.set("config.test.number", 100, "0.0.1");

// double
CORE_CONFIG.set("config.test.chance", 0.1, "0.0.1");

// list
CORE_CONFIG.set("config.test.list", new String[]{"my_world", "my_world_nether"}, "0.0.1");

Saving

// save the config file with the version 0.0.1
CORE_CONFIG.setVersion("0.0.1", true);

How I can read from the config?

// String
CORE_CONFIG.getString("config.test.name");

// boolean
CORE_CONFIG.getBool("config.test.chance");

...

How I can upgrade my config automatic?

If you want to change or add a new entry, then you need to increase the version.
Dont forget to change the version in the method setVersion to the newest.

Information

Server Owner

Developer

Clone this wiki locally