diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-08-05 02:13:34 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-08-05 02:13:34 +0900 |
| commit | f2cb1a244c10adbce7eb7e40b6dcf2c0c03ca83a (patch) | |
| tree | 26e72f48e38f6d7648c3cecac5043665c92ffe61 | |
| parent | c940b9ad7e50e9809e1aded520f0f5c4aff0e741 (diff) | |
| download | LunaticChat-f2cb1a244c10adbce7eb7e40b6dcf2c0c03ca83a.tar.gz LunaticChat-f2cb1a244c10adbce7eb7e40b6dcf2c0c03ca83a.tar.bz2 LunaticChat-f2cb1a244c10adbce7eb7e40b6dcf2c0c03ca83a.zip | |
fix: start on defaults when config.yml cannot be read
readText sat outside ConfigManager, so the documented "fall back to defaults"
never covered the read itself. saveDefaultConfig only logs when it fails to
write the file, so the read can still find nothing there - and the IOException
then escaped onEnable and Paper disabled the plugin outright.
Co-Authored-By: Claude <noreply@anthropic.com>
| -rw-r--r-- | platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt index 710123f..3f9cb76 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt @@ -58,7 +58,7 @@ class LunaticChat : override fun onEnable() { saveDefaultConfig() - configuration = ConfigManager(logger).loadConfiguration(dataFolder.resolve("config.yml").readText()) + configuration = ConfigManager(logger).loadConfiguration(readConfigFile()) if (configuration.debug) { logger.warning("LunaticChat is running in debug mode.") @@ -102,6 +102,21 @@ class LunaticChat : } /** + * Reads config.yml, or an empty document when it cannot be read. + * + * [saveDefaultConfig] only logs when it fails to write the file, so the read can still find + * nothing there. Handing the parser an empty document starts the plugin on its defaults + * instead of throwing out of [onEnable] and disabling it outright. + */ + private fun readConfigFile(): String { + val file = dataFolder.resolve("config.yml") + return runCatching { file.readText() }.getOrElse { e -> + logger.severe("Could not read ${file.path}, falling back to defaults: ${e.message}") + "" + } + } + + /** * Registers all commands based on enabled features. */ private fun registerCommands() { |
