NoonieConfigs is a simple library to manage configurations. It does this by using concrete classes to represent configuration files. NoonieConfigs also uses a unique system, which helps the user set and update to valid values.
NoonieConfigs offers:
- Automatic updates for configs. (If a configuration class is updated, the configuration saved in the storage will also update.)
- Automatic fallback value replacement. (If a configuration was loaded, and the values are illegal, fallback values can replace those illegal values.)
To set up a basic configuration environment, a service must be instantiated:
public class MyJavaPlugin {
public static void main(String[] args) throws Exception {
Path pathToConfigFolder = Path.of(/*Your path here.*/);
ConfigService<Object> configService = DefaultConfigServices
.createJsonConfigService(pathToConfigFolder);
configService.initialize();
}
}
To set up a configuration class, make sure the class is annotated with @Config
, like so:
@Config(name = "MyConfig")
public class MyConfig {
private final String food = "Pizza";
private final int favoriteInteger = 100;
}
Note: In the configuration class it is recommended to set up default values which can be used as fallback values.
To save a configuration, all that needs to be done is:
configService.save(myConfig);
To load a configuration from storage, it requires a little few more steps:
Firstly, the configuration must exist already.
Secondly, the configuration must be a valid representation of the class.
Note: To enforce the second step, load the configuration with a fallback object.
MyConfig myConfig;
if (configService.isSaved(MyConfig.class)) {
myConfig = configService.loadWithFallback(new MyConfig());
} else {
myConfig = new MyConfig();
}