-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Welcome to the Supervisor Configuration Wiki! This guide will help you understand the configuration system in Supervisor, including how to create configuration files and utilize different configuration services.
Supervisor provides an easy way to handle configuration files, allowing you to store plugin-specific settings and other data in a structured way. The configurations can be defined in YAML, TOML, or JSON formats, depending on your requirements.
To create a configuration class, use the @Configuration annotation. This annotation allows you to specify details about the configuration file, including its name and the service that will manage the configuration (e.g., YAML, TOML, or JSON).
In the following example, we'll create a DummyConfig class with a YAML configuration file named dummy.yml.
package com.vertmix.supervisor.core.bukkit.dummy.config;
import com.vertmix.supervisor.configuration.Configuration;
import com.vertmix.supervisor.configuration.yml.YamlConfigService;
@Configuration(fileName = "dummy.yml", service = YamlConfigService.class)
public class DummyConfig {
}In this example, the DummyConfig class is annotated with @Configuration, and the file name (dummy.yml) and service (YamlConfigService) are specified. This means that the configuration will be saved in a file named dummy.yml and managed by the YamlConfigService.
You can also specify a custom path for your configuration file by adding the path parameter to the @Configuration annotation.
@Configuration(path = "/config/", fileName = "dummy.yml", service = YamlConfigService.class)
public class DummyConfig {
}In this example, the configuration file will be saved in a custom folder (/config/). This is useful if you want to organize your configurations in a specific directory structure.
Supervisor provides several configuration services that allow you to handle different file formats for your configurations. These services are responsible for reading, writing, and managing the configuration data.
- YamlConfigService: Handles YAML-based configuration files. YAML is a human-readable format that is widely used for configuration files.
- TomlConfigService: Handles TOML-based configuration files. TOML is a simple and easy-to-read configuration format.
- JsonConfigService: Handles JSON-based configuration files. JSON is a lightweight data-interchange format, ideal for structured data.
You can use any of these services based on your preferred configuration format. Simply specify the service in the @Configuration annotation when creating your configuration class.
Here's an example of how to create and use a YAML configuration in your plugin:
package com.vertmix.supervisor.core.bukkit.dummy.config;
import com.vertmix.supervisor.configuration.Configuration;
import com.vertmix.supervisor.configuration.yml.YamlConfigService;
@Configuration(fileName = "dummy.yml", service = YamlConfigService.class)
public class DummyConfig {
// Define configuration fields here
private String welcomeMessage;
private int maxPlayers;
// Getters and setters for the fields
public String getWelcomeMessage() {
return welcomeMessage;
}
public void setWelcomeMessage(String welcomeMessage) {
this.welcomeMessage = welcomeMessage;
}
public int getMaxPlayers() {
return maxPlayers;
}
public void setMaxPlayers(int maxPlayers) {
this.maxPlayers = maxPlayers;
}
}In this example, the DummyConfig class defines two configuration fields: welcomeMessage and maxPlayers. You can access these fields in your plugin code to read or modify the configuration values.
Once you've defined your configuration class, you need to load it in your plugin's main class to use it. You can use the SupervisorLoader to manage the loading of configuration files.
Here's an example of how to load a configuration in your main plugin class:
package com.vertmix.supervisor.core.bukkit;
import com.vertmix.supervisor.loader.SupervisorLoader;
import com.vertmix.supervisor.core.bukkit.dummy.config.DummyConfig;
import org.bukkit.plugin.java.JavaPlugin;
import static com.vertmix.supervisor.core.bukkit.BukkitProvider.bukkit;
public class DummyPlugin extends JavaPlugin {
private DummyConfig dummyConfig;
@Override
public void onEnable() {
SupervisorLoader.register(bukkit(this));
dummyConfig = SupervisorLoader.load(DummyConfig.class);
// Example usage of the configuration
getLogger().info("Welcome Message: " + dummyConfig.getWelcomeMessage());
}
}In this example, the DummyPlugin class loads the DummyConfig class using SupervisorLoader.load(). You can then use the configuration fields (welcomeMessage in this case) within your plugin.
Supervisor's configuration system provides a flexible way to manage your plugin's settings, allowing you to choose between YAML, TOML, and JSON formats. By using annotations and configuration services, you can easily define and load configuration files, making it easier to manage plugin settings in a structured manner.
If you need further assistance or have any questions, feel free to contact us or contribute to the project!
If you're interested in contributing to the Supervisor project, feel free to submit pull requests or raise issues on GitHub. We welcome suggestions and improvements from the community.
The Supervisor project is licensed under the MIT License. See the LICENSE file for more information.
For further questions or suggestions, contact us at support@vertmix.com.
Thank you for being part of the Supervisor community!