improve type adapters for CustomCommand

This commit is contained in:
nikky 2018-06-24 14:57:42 +02:00
parent f24ba763ac
commit 6af52cc58e
2 changed files with 9 additions and 6 deletions

View File

@ -77,8 +77,7 @@ object CommandConfig {
.registerTypeAdapter(CustomCommand::class.java) { jsonObj ->
with(CustomCommand.DEFAULT) {
CustomCommand(
type = jsonObj.get(String::class.java, "type")?.let { CommandType.valueOf(it) }
?: type,
type = jsonObj.get(CommandType::class.java, "type") ?: type,
execute = jsonObj.get(String::class.java, "execute") ?: execute,
response = jsonObj.get(String::class.java, "response") ?: response,
permLevel = jsonObj.get(Double::class.java, "permLevel") ?: permLevel,
@ -86,11 +85,15 @@ object CommandConfig {
timeout = jsonObj.get(Int::class.java, "timeout") ?: timeout,
defaultCommand = jsonObj.get(Boolean::class.java, "defaultCommand") ?: defaultCommand,
execOp = jsonObj.get(Boolean::class.java, "execOp") ?: execOp,
argumentsRegex = jsonObj.get(String::class.java, "argumentsRegex")?.toRegex()
?: argumentsRegex
argumentsRegex = jsonObj.get(Regex::class.java, "argumentsRegex") ?: argumentsRegex
)
}
}
.registerPrimitiveTypeAdapter(CommandType::class.java) {jsonObj ->
CommandType.valueOf(jsonObj.toString())
}
.registerPrimitiveTypeAdapter(Regex::class.java) {jsonObj ->
jsonObj.toString().toRegex()
}
.build()

View File

@ -63,7 +63,7 @@ object PermissionConfig {
}
configFile.writeText(jsonObject.toJson(true, true))
return true
}
}