Skip to content

Configuration

frosxt edited this page Apr 14, 2026 · 1 revision

Configuration

PrisonCore exposes two config-related services to modules. CoreConfig is the parsed core.yml — read-only, populated at boot, used by modules that need to know the active storage backend or other platform-wide settings. ConfigService is a generic typed YAML loader for files outside core.yml.

For your own module's config, you have two choices: use ConfigService and let the platform manage your file, or use Bukkit's YamlConfiguration directly and own the file yourself. Both are valid. The platform doesn't force one or the other.

CoreConfig

com.github.frosxt.prisoncore.kernel.config.CoreConfig

Resolved through the service container:

final CoreConfig coreConfig = context.services().resolve(CoreConfig.class);

Methods:

public boolean debugMode();
public String storageBackend();
public Map<String, String> storageProperties();
public String defaultCurrencyId();

debugMode() reflects debug: true|false in core.yml. The kernel itself logs differently when debug mode is on; your module is free to do the same.

storageBackend() returns the backend type chosen platform-wide. Match against "json", "sqlite", "sql", or "mongo" (or whatever custom factories have been registered).

storageProperties() returns every key/value under storage: in core.yml except backend itself. Backend-specific settings (sqlite file path, sql url, mongo uri, credentials) flow through here. Read the keys you need; ignore the rest.

defaultCurrencyId() returns the platform-wide default currency identifier. Modules that integrate with the economy use this when no specific currency is named.

CoreConfig is immutable. There is no set(...) method. If admins edit core.yml and want a reload, that's a kernel-level concern.

ConfigService

com.github.frosxt.prisoncore.config.api.ConfigService

public interface ConfigService {
    Map<String, Object> load(String name);
    void save(String name, Map<String, Object> data);
    void reload(String name);
    Optional<Object> get(String name, String key);
    void set(String name, String key, Object value);
}

A generic YAML store keyed by file stem (no extension). The platform handles the actual file I/O.

final ConfigService config = context.services().resolve(ConfigService.class);
final Map<String, Object> data = config.load("hello");
final Optional<Object> theme = config.get("hello", "ui.theme");

load(name) reads the entire YAML file as a nested Map<String, Object>. The map structure mirrors the YAML structure, so a section becomes a nested map and a list becomes a List<Object>.

save(name, data) serializes the map back to YAML. Use this if you want to write config from code (not common).

reload(name) re-reads the file from disk, picking up edits an admin made while the server was running.

get(name, key) is a convenience for fetching a single value by dotted path. config.get("hello", "ui.theme") is equivalent to navigating the nested map yourself but reads more cleanly.

set(name, key, value) writes a single value by dotted path. Combined with save, this gives you a basic key/value config without manually constructing maps.

ConfigValidator

com.github.frosxt.prisoncore.config.api.ConfigValidator<T>

public interface ConfigValidator<T> {
    ConfigValidationReport validate(T config);
}

A small contract for validating typed config objects. Implement this when you want a clean separation between "load the YAML" and "check the loaded object makes sense." Use the report to surface validation errors to the admin via your module's logger.

com.github.frosxt.prisoncore.config.api.ConfigValidationReport carries the validation outcome and any errors found.

ReloadPolicy

com.github.frosxt.prisoncore.config.api.ReloadPolicy

An enum capturing how a config can be reloaded:

  • STATIC — only on full restart. Most settings should be this by default.
  • RELOADABLE — supports an explicit reload command without restart.
  • HOT_SWAPPABLE — the platform watches the file and reloads automatically on change.

This is metadata. The enum tells callers what to expect; the actual reload mechanism is up to you.

When to use what

If you need a value from core.yml, use CoreConfig. Don't read core.yml yourself.

If your config has structure you want to model with records (the way EconomyConfig does in the Economy module), parse YamlConfiguration directly with Bukkit. It's three lines of code and you keep the typed shape. Don't try to wedge complex typed config through ConfigService.get.

Clone this wiki locally