-
-
Notifications
You must be signed in to change notification settings - Fork 3
EldoConfig
The Eldoconfig provides a more or less simple access to the plugin config and some other basic functions.
It also allows you to easily manage multiple config files e.g. when you need per world configs.
You can check the debug state of your plugin at any time.
You can even check it before your config is loaded.
With the EldoConfig#isDebug(Class<? extends Plugin>)
method you can directly request the debug state of the plugin.
However if something went wrong your debug state will always be false per default.
As the debug state, a config holds a version.
Every config should have a version. If no version is found this will be -1.
The current version of the config can be retrieved via EldoConfig#getVersion()
.
Although the term main
got a bit raped in the past I use this term here.
The main config refers to your config.yml inside your plugin directory. This is the config you will need most of the time.
You can retrieve it by calling EldoConfig#getMainConfig(Class<? extends EldoConfig>)
. This method will always return the main config.
You can create your own EldoConfig by extending our EldoConfig Class. By doing this you have may want to implement some methods. What and how to implement them will be explained in the following part.
public class Configuration extends EldoConfig{
public Configuration(Plugin plugin) {
super(plugin);
}
@Override
protected void saveConfigs() {
}
@Override
protected void reloadConfigs() {
}
@Override
protected void init() {
}
}
Since your own config gets wrapped saving and loading your config changes a bit. Lets start with loading.
If you want you can initialize your config by overriding EldoConfig#init()
.
This method will be called before loading your config. It will only be executed on the main config file creation.
You could also create and/or load external configs here. To do this continue reading.
First: Reloading and loading your config is the same. Whenever I refer to reloading I mean loading as well.
When creating your config file the reload method is invoke. This method does two things.
- Reload your config.yml
- Cache it inside the plugin
- Load all registered external configs (Load your external configs by overriding the init method)
- Call the
EldoConfig#reloadConfigs
method.
This means that after creating a EldoConfig, you config.yml is already ready to go.
You can customize your loading routing implementing the EldoConfig#reloadconfigs()
method.
You can load external configs here for example.
Like mentioned above it is not necessary to reload configs which are once loaded.
Loading a config file which is not your config.yml is pretty easy.
Since all external configs are stored in your main config file you can only load external configs via your main config instance.\
Loading an external config is done by two methods.
EldoConfig#loadConfig(String, Consumer<FileConfiguration>, boolean)
or EldoConfig#loadConfig(String, Consumer<FileConfiguration>, boolean)
The first one takes a string and will append .yml
to your input. The second takes an path to your yml file. Everything is relative to your plugin directory.
The loadConfig method grantees that you will get a FileConfiguration.
This means that a present config is loaded or a new one is created.
If your file was created the Consumer will be applied to initialize your FileConfiguration with default values.
The load config method will also create missing directories.
The loadConfig method will always return the loaded file if it is already loaded. Use the reload boolean to force a reload.
To save your plugin you have to call the method EldoConfig#save()
.
This method will call two other methods.
The first one is EldoConfig#saveConfig()
. This method has to be implemented by you. If you don't write directly on your FileConfiguration you have to save your stuff here. E.g. when your use ConfigurationSerializable, which I highly recommend.
After this the configs will be written on disk by the EldoConfig#writeConfigs()
.
This will save your config.yml and your external configs.