-
Notifications
You must be signed in to change notification settings - Fork 0
2. 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:
- Create missing files and keys
- Apply YAML values to your fields
- Validate values and apply defaults or clamps where necessary
- Write the configuration back to disk
- Add missing keys and comments while preserving unknown keys
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";
}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);
}
}Your settings instance is a normal Java object:
if (settings.debug) {
// ...
}
int size = settings.cacheSize;
String backend = settings.backend;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.
Defines where the configuration file is stored relative to the plugin data folder.
This annotation is required.
Maps a Java field to a YAML path.
Example:
@ConfigKey("database.host")
public String host = "localhost";Defines configuration sections for structured configuration objects.
Adds comments to generated YAML configuration.
Restricts a String field to a predefined set of allowed values.
@AllowedValues({"json", "h2", "mysql"})
public String backend = "json";Defines numeric validation boundaries.
@Min(1)
@Max(100)
public int amount = 10;When combined with @Min or @Max, values outside the configured range are clamped to the nearest valid value.
Ensures that a field value is not null.
If a null value is encountered, VertexCore can fall back to the configured default.
Validates String fields against a regular expression.
- Use configuration objects as database settings in the Database System
- Return to Getting Started
- Return to the Wiki Home
VertexCore 1.1.0 · Repository · Releases · Issues