this really should not break
This commit is contained in:
parent
602762f371
commit
88bee22010
|
@ -56,7 +56,8 @@ val Exception.stackTraceString: String
|
|||
return sw.toString()
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T {
|
||||
instance.info("type: ${T::class.java.name} key: $key default: $default")
|
||||
return putDefault(key, default, comment)!!
|
||||
fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T {
|
||||
instance.info("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default")
|
||||
putDefault(key, default, comment)!!
|
||||
return get(default.javaClass, key)!!
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import matterlink.instance
|
|||
import matterlink.stackTraceString
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
lateinit var cfg: BaseConfig.MatterLinkConfig
|
||||
lateinit var baseCfg: BaseConfig
|
||||
|
@ -358,16 +359,16 @@ data class BaseConfig(val rootDir: File) {
|
|||
jankson.load(configFile)
|
||||
} catch (e: SyntaxError) {
|
||||
instance.error("error loading config: ${e.completeMessage}")
|
||||
Marshaller.getFallback().serialize(MatterLinkConfig()) as JsonObject
|
||||
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
|
||||
} catch (e: FileNotFoundException) {
|
||||
instance.error("creating config file $configFile")
|
||||
configFile.createNewFile()
|
||||
Marshaller.getFallback().serialize(MatterLinkConfig()) as JsonObject
|
||||
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
|
||||
}
|
||||
instance.info("finished loading $jsonObject")
|
||||
|
||||
val tmpCfg = try {
|
||||
cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||
//cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||
jankson.fromJson(jsonObject, MatterLinkConfig::class.java).apply {
|
||||
configFile.writeText(jsonObject.toJson(true, true))
|
||||
instance.info("loaded config: $this")
|
||||
|
@ -378,6 +379,10 @@ data class BaseConfig(val rootDir: File) {
|
|||
} catch (e: IllegalStateException) {
|
||||
instance.error(e.stackTraceString)
|
||||
MatterLinkConfig()
|
||||
} catch (e: NullPointerException) {
|
||||
instance.error("error loading config: ${e.stackTraceString}")
|
||||
MatterLinkConfig()
|
||||
exitProcess(-1)
|
||||
}
|
||||
|
||||
// val defaultJsonObject = jankson.load("{}")
|
||||
|
|
|
@ -4,7 +4,6 @@ import blue.endless.jankson.Jankson
|
|||
import blue.endless.jankson.JsonObject
|
||||
import blue.endless.jankson.impl.Marshaller
|
||||
import blue.endless.jankson.impl.SyntaxError
|
||||
import matterlink.getOrDefault
|
||||
import matterlink.instance
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
@ -84,7 +83,7 @@ object PermissionConfig {
|
|||
|
||||
fun add(platform: String, userid: String, powerlevel: Double, comment: String? = null) {
|
||||
val platformObject = jsonObject.getObject(platform) ?: JsonObject()
|
||||
platformObject.getOrDefault(userid, powerlevel, comment)
|
||||
platformObject.putDefault(userid, powerlevel, comment)
|
||||
jsonObject[platform] = platformObject
|
||||
|
||||
perms.clear()
|
||||
|
|
Loading…
Reference in New Issue