diff --git a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt index 6a1c6d6..a62ddd8 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt @@ -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 diff --git a/core/src/main/kotlin/matterlink/config/CommandConfig.kt b/core/src/main/kotlin/matterlink/config/CommandConfig.kt index c0d1237..2b9869e 100644 --- a/core/src/main/kotlin/matterlink/config/CommandConfig.kt +++ b/core/src/main/kotlin/matterlink/config/CommandConfig.kt @@ -10,7 +10,7 @@ import matterlink.instance import matterlink.stackTraceString import java.io.File -typealias CommandMap = Map +typealias CommandMap = MutableMap 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() {}.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") diff --git a/gradle.properties b/gradle.properties index f5de1d5..0e476e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file