Merge pull request #12 from SKBotNL/main

Make loadConfig create plugin folder with config if it doesn't exist and log exception type when loading config fails
This commit is contained in:
NotAlexNoyle authored and GitHub committed 2026-04-13 03:45:21 -04:00
commit bbf2c2d7e4
1 file changed
+6 -2
@@ -12,7 +12,11 @@ object Config {
fun loadConfig(): ConfigModel? {
return try {
configMapper.readValue(File(plugin.dataFolder, "config.yml"), ConfigModel::class.java)
val file = File(plugin.dataFolder, "config.yml")
if (!file.exists()) {
plugin.saveDefaultConfig()
}
configMapper.readValue(file, ConfigModel::class.java)
} catch (e: ValueInstantiationException) {
if (e.cause !is NullPointerException) throw e
// Hacky but seems to be the only way
@@ -26,7 +30,7 @@ object Config {
)
null
} catch (e: JacksonException) {
plugin.logger.severe("Something went wrong while loading the config:\n${e.message}")
plugin.logger.severe("Something went wrong while loading the config (${e::class.simpleName}):\n${e.message}")
null
}
}