Adding your own configuration
The ConfigManager class contains methods that can be helpful when creating new configurations. To start, we will need to create a class that inherits from ConfigManager
public class MyConfig extends ConfigManager<MyPlugin> {
protected MyConfig(MyPluginplugin) {
super(plugin);
}
}
It is recommended to follow the singleton pattern within this class. A complete example would be:
public class MyConfig extends ConfigManager<MyPlugin> {
private static MyConfig INSTANCE;
private MyConfig(MyPlugin plugin) {
super(plugin);
}
public static MyConfig register(MyPlugin plugin){
MyConfig config = new MyConfig(plugin);
config.tryLoad("myconfigfile.yml", ((configFile, configuration) -> {
...
}), ((configFile, configuration) -> {
...
}));
INSTANCE = config;
return INSTANCE;
}
public static MyConfig getInstance(){
return INSTANCE;
}
}
Now, within the register method, use the tryLoad method to load a new configuration.
Last updated