-
Notifications
You must be signed in to change notification settings - Fork 6
Configuration API
BlueSlimeCore uses ConfigurationManager objects to assist you with configuration files.
You can make your plugin's main class extend com.github.sirblobman.api.plugin.ConfigurablePlugin
instead of JavaPlugin
to use the built-in method:
getConfigurationManager()
You can create a custom instance in your own plugin class if you don't want to use the ConfigurablePlugin as a parent.
import org.bukkit.plugin.java.JavaPlugin;
import com.github.sirblobman.api.configuration.ConfigurationManager;
public final class YourPlugin extends JavaPlugin {
private final ConfigurationManager configurationManager;
public YourPlugin() {
this.configurationManager = new ConfigurationManager(this);
}
public ConfigurationManager getConfigurationManager() {
return this.configurationManager;
}
}
Default configurations are files that are inside of the plugin jar and contain default values. You can create them at startup by using the following method in your plugin class. Default configurations will not override existing files.
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("example.yml");
}
Reloading a configuration means overriding the values in memory with values currently on the disk. Reloading is usually done after a user finishes editing a configuration. You can reload configuration files with the following method:
public void reloadConfiguration() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("example.yml");
}
Reading a configuration allows you to get values. ConfigurationManager uses the Bukkit YamlConfiguration objects, so you don't have to learn anything new if you already know this system.
public void readValues() {
ConfigurationManager configurationManager = getConfigurationManager();
YamlConfiguration configuration = configurationManager.get("example.yml");
String exampleValue = configuration.getString("example-path");
// Do something with the value
}
Sometimes you need to save values in memory to the disk. You should not do this for user-editable files, but for data files it is sometimes necessary.
public void setCustomValues() {
ConfigurationManager configurationManager = getConfigurationManager();
YamlConfiguration configuration = configurationManager.get("example.yml");
configuration.set("example-path", "example value");
configurationManager.save("example.yml")
}
You can find out more information about the configuration API in BlueSlimeCore by reviewing the source files