Skip to content

From Plugin-Local Config Loaders

If your plugin already has a local ConfigService, it probably owns more than raw getters. It usually also owns:

  • saveResource(...)
  • file version bumps
  • default merge logic
  • settings.yml plus lang.yml pairing
  • module file maps
  • reload orchestration
  • runtime fallback rules

Replace those responsibilities with DaisyConfig in layers.

  • raw getString(...) lookups
  • manual nested-section traversal

With:

  • typed codecs
  • DaisyConfigHandle<T>
  • yamlConfigHandle(...)

Before:

  • reload file
  • decode manually
  • hope the runtime does not switch to a half-valid state

After:

  • DaisyConfigHandle<T>
  • DaisyManagedConfigHandle<T>
  • DaisyModuleHandle<S>

All keep the last good runtime value live on failure.

Before:

  • copy defaults on first startup
  • keep helper code for every config file

After:

  • unmanaged: ensureDefaultConfigResource(...)
  • managed: let DaisyManagedYamlFile<T> create the file from bundled defaults automatically

Before:

  • read an integer manually
  • special-case missing versions
  • rename and remove keys yourself

After:

  • currentVersion
  • versionKey
  • DaisyYamlMigrations.rename(...)
  • move(...)
  • remove(...)
  • setDefault(...)

Absent config_version is treated as version 1.

Before:

  • Map<String, File> for settings
  • another map for lang
  • plugin-local category/module conventions

After:

  • DaisyModules.load(...)
  • DaisyModuleDefinition<S>
  • DaisyModuleRegistry

6. Replace local settings.yml plus lang.yml pairing

Section titled “6. Replace local settings.yml plus lang.yml pairing”

Before:

  • two separate reload calls
  • plugin-local bundling logic

After:

  • one DaisyModuleHandle<S>
  • one current.settings
  • one textSource

7. Replace local migration code with DaisyYamlMigrations

Section titled “7. Replace local migration code with DaisyYamlMigrations”

Use a managed file:

val spawnSettings =
DaisyManagedYamlFile(
id = "commands/spawn/settings",
path = "modules/commands/spawn/settings.yml",
codec = spawnSettingsCodec,
currentVersion = 2,
migrations = listOf(
DaisyYamlMigrations.move(1, 2, "spawn-delay", "spawn.delay"),
),
)

That replaces plugin-local code for:

  • missing-key merge
  • version upgrades
  • rename/remove/default migrations
  • change reporting

The goal is practical: remove the local config service and let DaisyConfig own the config lifecycle directly.