keep track of default commands for updating
use nullable variables because gson is stupid
This commit is contained in:
parent
fd7fd69306
commit
1400627187
|
@ -8,17 +8,18 @@ import matterlink.lazyFormat
|
|||
|
||||
data class CustomCommand(
|
||||
val type: CommandType = CommandType.RESPONSE,
|
||||
val execute: String = "",
|
||||
val response: String = "",
|
||||
val execute: String? = null,
|
||||
val response: String? = null,
|
||||
override val permLevel: Double = 0.0,
|
||||
override val help: String = "",
|
||||
val allowArgs: Boolean = true,
|
||||
val timeout: Int = 20
|
||||
val timeout: Int = 20,
|
||||
val defaultCommand: Boolean? = null
|
||||
) : IBridgeCommand {
|
||||
val alias: String
|
||||
get() = BridgeCommandRegistry.getName(this)!!
|
||||
|
||||
var lastUsed: Int = 0
|
||||
@Transient private var lastUsed: Int = 0
|
||||
override fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean {
|
||||
if (!allowArgs && args.isNotBlank()) return false
|
||||
|
||||
|
@ -45,7 +46,7 @@ data class CustomCommand(
|
|||
}
|
||||
CommandType.RESPONSE -> {
|
||||
MessageHandlerInst.transmit(ApiMessage()
|
||||
.setText(response.lazyFormat(getReplacements(user, userId, server, args)))
|
||||
.setText((response ?: "").lazyFormat(getReplacements(user, userId, server, args)))
|
||||
)
|
||||
true
|
||||
}
|
||||
|
@ -57,8 +58,8 @@ data class CustomCommand(
|
|||
*/
|
||||
override fun validate(): Boolean {
|
||||
val typeCheck = when (type) {
|
||||
CommandType.EXECUTE -> execute.isNotBlank()
|
||||
CommandType.RESPONSE -> response.isNotBlank()
|
||||
CommandType.EXECUTE -> execute?.isNotBlank() ?: false
|
||||
CommandType.RESPONSE -> response?.isNotBlank() ?: false
|
||||
}
|
||||
if (!typeCheck) return false
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import matterlink.instance
|
|||
import matterlink.stackTraceString
|
||||
import java.io.File
|
||||
|
||||
typealias CommandMap = Map<String, CustomCommand>
|
||||
typealias CommandMap = MutableMap<String, CustomCommand>
|
||||
|
||||
object CommandConfig {
|
||||
private val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
||||
|
@ -22,33 +22,38 @@ object CommandConfig {
|
|||
execute = "forge tps",
|
||||
help = "Print server tps",
|
||||
allowArgs = false,
|
||||
timeout = 200
|
||||
timeout = 200,
|
||||
defaultCommand = true
|
||||
),
|
||||
"list" to CustomCommand(
|
||||
type = CommandType.EXECUTE,
|
||||
execute = "list",
|
||||
help = "List online players",
|
||||
allowArgs = false
|
||||
allowArgs = false,
|
||||
defaultCommand = true
|
||||
),
|
||||
"seed" to CustomCommand(
|
||||
type = CommandType.EXECUTE,
|
||||
execute = "seed",
|
||||
help = "Print server world seed",
|
||||
allowArgs = false
|
||||
allowArgs = false,
|
||||
defaultCommand = true
|
||||
),
|
||||
"uptime" to CustomCommand(
|
||||
type = CommandType.RESPONSE,
|
||||
permLevel = 1.0,
|
||||
response = "{uptime}",
|
||||
help = "Print server uptime",
|
||||
allowArgs = false
|
||||
allowArgs = false,
|
||||
defaultCommand = true
|
||||
),
|
||||
"whoami" to CustomCommand(
|
||||
type = CommandType.RESPONSE,
|
||||
response = "server: `{server}` userid: `{userid}` user: `{user}`",
|
||||
help = "Print debug user data",
|
||||
allowArgs = false,
|
||||
timeout = 200
|
||||
timeout = 200,
|
||||
defaultCommand = true
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -64,6 +69,13 @@ object CommandConfig {
|
|||
|
||||
try {
|
||||
commands = gson.fromJson(configFile.readText(), object : TypeToken<CommandMap>() {}.type)
|
||||
commands.filterValues { it.defaultCommand ?: false }.forEach { commands.remove(it.key) }
|
||||
default.forEach { k, v ->
|
||||
if(!commands.containsKey(k)){
|
||||
commands[k] = v
|
||||
}
|
||||
}
|
||||
configFile.writeText(gson.toJson(commands))
|
||||
} catch (e: JsonSyntaxException) {
|
||||
instance.fatal(e.stackTraceString)
|
||||
instance.fatal("failed to parse $configFile using last good values as fallback")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod_name = MatterLink
|
||||
mod_version = 1.5.7
|
||||
mod_version = 1.5.8
|
||||
forgelin_version = 1.6.0
|
||||
curse_id = 287323
|
||||
curse_release_type = beta
|
Loading…
Reference in New Issue