Skip to content

A thread-safe YAML configuration library which provides reload and auto-save capabilities. Also very ✨professional✨.

License

Notifications You must be signed in to change notification settings

BoboLaboratories/BoboConfig

Repository files navigation

BoboLabs

We write code, you enjoy it :D

 wonders = BoboLabs
   .add(glowy)
   .add(stami)
   .code();
 
 you.enjoy(wonders);


BoboConfig

A thread-safe YAML 1.1 configuration library which provides reload and auto-save capabilities. Also very ✨professional✨.

Main characteristics

  • finely tuned for Minecraft development (Bukkit, Spigot, Paper, Folia, Bungee, Velocity, etc.), but also compatible with any sort 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 configuration files
  • both manual and auto save support
  • fully reloadable configurations

Vanilla Java Spigot/Paper BungeeCord Velocity Folia
✔️ ✔️ ✔️ ✔️ 💡

Usage

Here you can find the full Javadocs.

Gradle

repositories {
    maven { url = 'https://repo.bobolabs.net/releases' }
}

dependencies {
    implementation 'net.bobolabs.config:config:2.2.0'
}

Maven

<repositories>
    <repository>
        <id>bobolabs-releases</id>
        <url>https://repo.bobolabs.net/releases</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>net.bobolabs.config</groupId>
        <artifactId>config</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>

Simple usage

Configuration config = ConfigurationLoader
    .fromFile(getDataFolder(), "config.yml")
    .setDefaultResource("dir/config.yml")    // Optional
    .autoSave(true)                          // Optional
    .load();

String data = config.getString("my.data");

Full fledged usage

Describe the configuration files you need by declaring enum fields optionally marked with @Config.
@Config accepts several options to meet your needs, find out more here.

public enum Configs implements ConfigurationDescription {

    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);

The newly created manager can now be used to retrieve single configuration objects which can be used as normal.

Configuration config = configurationManager.load(Configs.GUI);
String guiTitle = config.getString("gui.title");
int guiSize = config.getInt("gui.size");

Example usage within a Spigot plugin

public final class MyPlugin extends JavaPlugin {

    private ConfigurationManager<Configs> configurationManager;

    @Override
    public void onEnable() {
        configurationManager = new ConfigurationManager<>(getDataFolder(), Configs.class);
        configurationManager.loadAll();
    }

    @Override
    public void onDisable() {
        if (configurationManager != null) {
            configurationManager.unloadAll();
            configurationManager = null;
        }
    }

    public @NotNull Configuration getConfiguration(@NotNull Configs config) {
        return configurationManager.get(config);
    }

}

About

A thread-safe YAML configuration library which provides reload and auto-save capabilities. Also very ✨professional✨.

Topics

Resources

License

Stars

Watchers

Forks

Languages