Config Ref
A live, reload-safe reference to a configuration instance of type T.
ConfigRef solves the stale-reference problem: when a config is reloaded, every class that holds a ConfigRef automatically sees the new values without re-injection or manual wiring.
Three ways to access the current config:
class DuelManager(private val config: ConfigRef<DuelsConfig>) {
// 1. Invoke operator — concise
fun getPort() = config().server.port
// 2. Property access — readable
fun getHost() = config.current.server.host
// 3. Kotlin delegate — zero-boilerplate
private val cfg: DuelsConfig by config
fun getMode() = cfg.game.defaultMode
}Content copied to clipboard
Selecting sub-sections as delegates:
class QueueManager(config: ConfigRef<DuelsConfig>) {
private val messages by config.selecting { it.messages }
private val cooldowns by config.selecting { it.commandCooldowns }
fun onJoin(player: Player) {
player.sendMessage(messages.prefix + messages.queueJoin)
// messages is always the latest value — never stale
}
}Content copied to clipboard
Reacting to changes:
config.onChange { old, new ->
if (old.game.maxDurationMinutes != new.game.maxDurationMinutes) {
restartActiveGames()
}
}Content copied to clipboard
Automatic file watching:
val config = YamlConfigManager.ref<DuelsConfig>(file)
.withAutoReload() // starts file watcher
.onChange { old, new -> logger.info("Config reloaded") }Content copied to clipboard
Since
1.0
Parameters
T
The configuration data class type.