In pom.xml:
<repositories>
<!-- other repositories -->
<repository>
<id>azalea-repo</id>
<name>Azalea Repository</name>
<url>https://azalealibrary.net/releases</url>
</repository>
</repositories>
<dependencies>
<!-- other dependencies -->
<dependency>
<groupId>net.azalealibrary</groupId>
<artifactId>configuration</artifactId>
<version>1.0</version>
</dependency>
</dependencies>Assume we want to a place to store some global configuration for a plugin. The first step is to declare a class implementing the Configurable interface:
classMyConfigurationimplementsConfigurable {
privatefinalProperty<Integer> aNumber = newProperty<>(PropertyType.INTEGER, () -> 1, "a_number", "some number description", true);
privatefinalProperty<String> aString = newProperty<>(PropertyType.STRING, () -> "text", "a_string", "some string description", false);
privatefinalListProperty<Vector> someVectors = newListProperty<>(PropertyType.VECTOR, ArrayList::new, "some_vectors", "some vector list description", false);
publicintgetNumber() {
returnaNumber.get();
}
publicStringgetString() {
returnaString.get();
}
publicList<Vector> getSomeVectors() {
returnsomeVectors.get();
}
@OverridepublicStringgetName() {
return"my_configuration";
}
@OverridepublicList<ConfigurableProperty<?, ?>> getProperties() {
returnList.of(aNumber, aString, someVectors);
}
}Now that we have defined some properties (aNumber, aString & someVectors), we want to load their values from a yml file.
We need to get a FileConfiguration object which represents a set of configuration data from a yml file, this is done via the AzaleaConfigurationApi#load method.
From a FileConfiguration object, we can then call the FileConfiguration#load method.
Once the data has been loaded, we can register it in order to configure the properties via the /configure command.
Here's an example of how we may load the configuration data into an instance of MyConfiguration and registering it:
classMyPluginextendsJavaPlugin {
publicfinalMyConfigurationmyConfiguration = newMyConfiguration();
@OverridepublicvoidonEnable() {
// get the associated `FileConfiguration` object of `MY_CONFIGURATION` ("<plugin_data_folder>/my_configuration.yml")FileConfigurationfileConfiguration = AzaleaConfigurationApi.load(this, myConfiguration.getName());
fileConfiguration.load(myConfiguration); // load properties from fileAzaleaConfigurationApi.register(myConfiguration); // register config to command
}
@OverridepublicvoidonDisable() {
// save `myConfiguration` as a yaml file ("<plugin_data_folder>/my_configurations.yml")FileConfigurationfileConfiguration = AzaleaConfigurationApi.load(this, myConfiguration.getName());
fileConfiguration.save(myConfiguration); // save properties to file
}
}Note, the api does not handle saving the data of your configuration, therefore it is up to the implementer handle that accordingly.
This can be done during the disabling cycle of the plugin, as shown in the example above.
Suppose we have a list of MyConfiguration configurations we want to load from the <plugin_data_folder>/my_configurations directory with AzaleaConfigurationApi#loadAll.
classMyPluginextendsJavaPlugin {
privatefinalList<MyConfiguration> configurations = newArrayList<>();
@OverridepublicvoidonEnable() {
// load all yaml files in "<plugin_data_folder>/my_configurations"for (FileConfigurationfileConfiguration : AzaleaConfigurationApi.getAllFileConfigurations(this, "my_configurations")) {
MyConfigurationconfiguration = newMyConfiguration(); // create a new `MyConfiguration` object for every configfileConfiguration.load(configuration); // load properties from fileAzaleaConfigurationApi.register(configuration); // register config to commandconfigurations.add(configuration);
}
}
@OverridepublicvoidonDisable() {
// save all configs as yaml files in "<plugin_data_folder>/my_configurations"for (MyConfigurationconfiguration : configurations) {
FileConfigurationfileConfiguration = AzaleaConfigurationApi.getAllFileConfiguration(this, "my_configurations", configuration.getName());
fileConfiguration.save(configuration); // save properties to file
}
}
}// TODO