BungeeCord includes a simple configuration API that supports YAML files.
Contents
Loading configuration files(top)
Unlike Bukkit, where you can use YamlConfiguration.loadConfiguration(), the BungeeCord API requires a configuration provider. The YAML provider is called YamlConfiguration. You can not create an instance of this class yourself; you must request it from the ConfigurationProvider:Code (Text):
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
Utilizing the Configuration instance(top)
Using the instance of Configuration should be straightforward. The most common parts of the API are already implemented, for example getString.Saving configuration files(top)
Once you know how to load the configuration file, this should be rather trivial:Code (Text):
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
Bits not provided(top)
Support for saving a default configuration(top)
This is easy to work around:Code (Text):
if (!getDataFolder().exists())
getDataFolder().mkdir();
File file = new File(getDataFolder(), "config.yml");
if (!file.exists()) {
try (InputStream in = getResourceAsStream("config.yml")) {
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
getDataFolder().mkdir();
File file = new File(getDataFolder(), "config.yml");
if (!file.exists()) {
try (InputStream in = getResourceAsStream("config.yml")) {
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}