Skip to content

2. Config System

Tebrox edited this page Sep 3, 2026 · 2 revisions

Config System

VertexCore provides an annotation-based configuration system.

Configuration files are defined using Java classes and annotations.

When a configuration is loaded, VertexCore will:

  1. Create missing files and keys
  2. Apply YAML values to your fields
  3. Validate values and apply defaults or clamps where necessary
  4. Write the configuration back to disk
  5. Add missing keys and comments while preserving unknown keys

Basic Example

import de.tebrox.vertexCore.config.ConfigObject;
import de.tebrox.vertexCore.config.annotation.*;

@StoreAt("config.yml")
@ConfigComment("Example plugin configuration")
public class Settings implements ConfigObject {

    @ConfigKey("debug")
    @ConfigComment("Enable debug logging")
    public boolean debug = false;

    @ConfigKey("cache.size")
    @ConfigComment("Maximum size of the in-memory cache")
    @Min(1)
    @Clamp
    public int cacheSize = 100;

    @ConfigKey("storage.backend")
    @AllowedValues({"json", "h2", "mysql"})
    @ConfigComment("Storage backend used by the database system")
    public String backend = "json";

    @ConfigKey("mysql.url")
    @ConfigComment("JDBC URL (only used if backend=mysql)")
    public String mysqlUrl = "jdbc:mysql://localhost:3306/test?useSSL=false";

    @ConfigKey("mysql.user")
    public String mysqlUser = "root";

    @ConfigKey("mysql.password")
    public String mysqlPassword = "password";
}

Loading the Config

import de.tebrox.vertexCore.config.Config;
import org.bukkit.plugin.java.JavaPlugin;

public final class MyPlugin extends JavaPlugin {

    private Config<Settings> config;
    private Settings settings;

    @Override
    public void onEnable() {
        this.config = new Config<>(this, Settings.class);
        this.settings = this.config.loadConfigObject();

        if (settings.debug) {
            getLogger().info("Debug logging is enabled");
        }

        getLogger().info("Cache size: " + settings.cacheSize);
    }
}

Accessing Config Values

Your settings instance is a normal Java object:

if (settings.debug) {
    // ...
}

int size = settings.cacheSize;
String backend = settings.backend;

Saving the Config

Fields can be modified and persisted back to disk:

settings.cacheSize = 250;
settings.debug = true;

config.saveConfigObject(settings);

VertexCore writes the YAML configuration while adding configured comments and preserving unknown keys.


Supported Annotations

@StoreAt("file.yml")

Defines where the configuration file is stored relative to the plugin data folder.

This annotation is required.

@ConfigKey("path.to.key")

Maps a Java field to a YAML path.

Example:

@ConfigKey("database.host")
public String host = "localhost";

@ConfigSection

Defines configuration sections for structured configuration objects.

@ConfigComment(...)

Adds comments to generated YAML configuration.

@AllowedValues({ ... })

Restricts a String field to a predefined set of allowed values.

@AllowedValues({"json", "h2", "mysql"})
public String backend = "json";

@Min(value) / @Max(value)

Defines numeric validation boundaries.

@Min(1)
@Max(100)
public int amount = 10;

@Clamp

When combined with @Min or @Max, values outside the configured range are clamped to the nearest valid value.

@NotNull

Ensures that a field value is not null.

If a null value is encountered, VertexCore can fall back to the configured default.

@Regex("pattern")

Validates String fields against a regular expression.


Next Steps

Clone this wiki locally