improve type adapters for CustomCommand
This commit is contained in:
parent
f24ba763ac
commit
6af52cc58e
|
@ -77,8 +77,7 @@ object CommandConfig {
|
||||||
.registerTypeAdapter(CustomCommand::class.java) { jsonObj ->
|
.registerTypeAdapter(CustomCommand::class.java) { jsonObj ->
|
||||||
with(CustomCommand.DEFAULT) {
|
with(CustomCommand.DEFAULT) {
|
||||||
CustomCommand(
|
CustomCommand(
|
||||||
type = jsonObj.get(String::class.java, "type")?.let { CommandType.valueOf(it) }
|
type = jsonObj.get(CommandType::class.java, "type") ?: type,
|
||||||
?: type,
|
|
||||||
execute = jsonObj.get(String::class.java, "execute") ?: execute,
|
execute = jsonObj.get(String::class.java, "execute") ?: execute,
|
||||||
response = jsonObj.get(String::class.java, "response") ?: response,
|
response = jsonObj.get(String::class.java, "response") ?: response,
|
||||||
permLevel = jsonObj.get(Double::class.java, "permLevel") ?: permLevel,
|
permLevel = jsonObj.get(Double::class.java, "permLevel") ?: permLevel,
|
||||||
|
@ -86,11 +85,15 @@ object CommandConfig {
|
||||||
timeout = jsonObj.get(Int::class.java, "timeout") ?: timeout,
|
timeout = jsonObj.get(Int::class.java, "timeout") ?: timeout,
|
||||||
defaultCommand = jsonObj.get(Boolean::class.java, "defaultCommand") ?: defaultCommand,
|
defaultCommand = jsonObj.get(Boolean::class.java, "defaultCommand") ?: defaultCommand,
|
||||||
execOp = jsonObj.get(Boolean::class.java, "execOp") ?: execOp,
|
execOp = jsonObj.get(Boolean::class.java, "execOp") ?: execOp,
|
||||||
argumentsRegex = jsonObj.get(String::class.java, "argumentsRegex")?.toRegex()
|
argumentsRegex = jsonObj.get(Regex::class.java, "argumentsRegex") ?: argumentsRegex
|
||||||
?: argumentsRegex
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.registerPrimitiveTypeAdapter(CommandType::class.java) {jsonObj ->
|
||||||
|
CommandType.valueOf(jsonObj.toString())
|
||||||
|
}
|
||||||
|
.registerPrimitiveTypeAdapter(Regex::class.java) {jsonObj ->
|
||||||
|
jsonObj.toString().toRegex()
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ object PermissionConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile.writeText(jsonObject.toJson(true, true))
|
configFile.writeText(jsonObject.toJson(true, true))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue