-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Fabio Nebbia edited this page May 12, 2023
·
9 revisions
BoboLabs YAML configuration library is a powerful and flexible cross-platform wrapper around md_5 configuration library inspired by SimplixStorage which also provides reload and auto-save capabilities. Also very ✨professional✨.
- finely tuned for Minecraft development (Bukkit, Spigot, Paper, Folia, Bungee, Velocity, etc.), but also compatible with any type of Java project
- flexible and customizable usage in both simple and complex projects (see the examples below)
- thread-safe (especially useful for Folia projects due to its multithreaded nature)
- easily handles multiple config files
- both manual and auto save support
- fully reloadable configurations
Configuration config = ConfigurationBuilder
.fromFile(getDataFolder(), "config.yml")
.setDefaultResource("dir/config.yml") // Optional
.autoSave(true) // Optional
.build();
String data = config.getString("my.data");
Describe the configuration files you need by declaring enum fields marked with @Config
which accepts several options to meet your needs, find out more here.
public enum Configs implements ConfigurationDescription {
@Config
CONFIG,
@Config(path = "configs/gui.yml")
GUI,
@Config(path = "configs/users.yml", autoSave = true)
USER_DATA,
@Config(path = "world.yml", defaultResource = "configs/world.yml", autoSave = true)
WORLD_SETTINGS,
@Config(path = "optional.yml", saveDefaultResource = false)
OPTIONAL_CONFIG
}
Then proceed by creating a ConfigurationManager
which will load the files according to the provided enum.
ConfigurationManager<Configs> configurationManager = new ConfigurationManager<>(getDataFolder(), Configs.class);
configurationManager.onEnable();
The newly created manager can now be used to retrieve single configuration objects which can be used as normal.
Configuration config = configurationManager.configuration(Configs.GUI);
String guiTitle = config.getString("gui.title");
int guiSize = config.getInt("gui.size");
public final class MyPlugin extends JavaPlugin {
private ConfigurationManager<Configs> configurationManager;
@Override
public void onEnable() {
configurationManager = new ConfigurationManager<>(getDataFolder(), Configs.class);
configurationManager.onEnable();
}
@Override
public void onDisable() {
if (configurationManager != null) {
configurationManager.onDisable();
configurationManager = null;
}
}
public @NotNull Configuration getConfiguration(@NotNull Configs config) {
return configurationManager.configuration(config);
}
}