-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
After you have added MDTConfig as a dependency and declared it in your plugin's plugin.yml as described in the README.md, getting started with MDTConfig is pretty easy and straightforward.
- Start with creating a ConfigManager by passing it your plugin instance, and then registering it.
public class TestPlugin extends JavaPlugin {
private static ConfigManager MANAGER;
@Override
public void onLoad() {
MANAGER = ConfigManager.register(new ConfigManager(this));
}
public static ConfigManager getConfigManager() {
return MANAGER;
}
}You can create the ConfigManager whatever way you like, but I usually prefer the way above.
Now you have to create a ConfigType. A ConfigType represents the configuration file where its associated ConfigSettings will be stored.
public static final ConfigType MAIN_CONFIG = new ConfigType("main_config.yml");MDTConfig automatically places configuration files inside the configs directory. Therefore, "main_config.yml" becomes configs/main_config.yml inside your plugin's data folder.
Now you can start creating your actual configuration settings. The class for this is ConfigSetting. NOTE: ConfigSettings must be registered within a ConfigManager
public static final ConfigSetting<Integer> EXTRA_XP_PER_ORB = MANAGER.register(
new ConfigSetting<>(
"Extra XP Per Orb", // The name of the Config Setting
"The extra xp gotten when picking xp orbs", // The description, will be shown in a comment
ConfigDataTypes.INTEGER, // Data Type
5, // Default Value,
MAIN_CONFIG // Config Type, the file that the setting will live in
)
);The name of the ConfigSetting will be normalized to an appropriate yml key.
The Config Setting above will generate this in configs/main_config.yml
# The extra xp gotten when picking xp orbs
# Default Value: 5 | Type: Whole Number
extra-xp-per-orb: 5There are a bunch of data types and configuration settings you can use. They are covered in the following pages.