From f2cb1a244c10adbce7eb7e40b6dcf2c0c03ca83a Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Wed, 5 Aug 2026 02:13:34 +0900 Subject: 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 --- .../kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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.") @@ -101,6 +101,21 @@ class LunaticChat : logger.info("LunaticChat disabled.") } + /** + * 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. */ -- cgit v1.2.1