From 040eec6cb2302b4dcc1666c5e2844363f1e9099f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:55:59 +0800 Subject: [PATCH 1/3] fix: command binds/autoDisable list page --- .../net/ccbluex/liquidbounce/features/command/Command.kt | 6 +++--- .../features/command/commands/client/CommandBinds.kt | 2 +- .../features/command/commands/module/CommandAutoDisable.kt | 4 ++-- src/main/resources/resources/liquidbounce/lang/zh_cn.json | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/Command.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/Command.kt index d310bf4542c..d9853fbc3dc 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/Command.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/Command.kt @@ -73,7 +73,7 @@ class Command( } fun result(key: String, vararg args: Any): MutableText { - return translation("$translationBaseKey.result.$key", *args) + return translation("$translationBaseKey.result.$key", args = args) } fun resultWithTree(key: String, vararg args: Any): MutableText { @@ -84,10 +84,10 @@ class Command( parentCommand = parentCommand.parentCommand } - return parentCommand!!.result(key, *args) + return parentCommand!!.result(key, args = args) } - return translation("$translationBaseKey.result.$key", *args) + return translation("$translationBaseKey.result.$key", args = args) } /** diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt index 06a22687655..a2df3dfe84e 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt @@ -73,7 +73,7 @@ object CommandBinds : CommandFactory { .build() ) .handler { command, args -> - val page = if (args.size > 1) { + val page = if (args.isNotEmpty()) { args[0] as Int } else { 1 diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt index fb2bea9a39f..de2546192a4 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt @@ -72,7 +72,7 @@ object CommandAutoDisable : CommandFactory { .build() ) .handler { command, args -> - val page = if (args.size > 1) { + val page = if (args.isNotEmpty()) { args[0] as Int } else { 1 @@ -129,7 +129,7 @@ object CommandAutoDisable : CommandFactory { .begin("module") .verifiedBy(ParameterBuilder.STRING_VALIDATOR) .autocompletedWith { begin, _ -> - ModuleAutoDisable.listOfModules.map { it.name }.toList().filter { it.startsWith(begin) } + ModuleAutoDisable.listOfModules.mapNotNull { it.name.takeIf { n -> n.startsWith(begin) } } } .required() .build() diff --git a/src/main/resources/resources/liquidbounce/lang/zh_cn.json b/src/main/resources/resources/liquidbounce/lang/zh_cn.json index 0c81b66dc42..54e5638c9a8 100644 --- a/src/main/resources/resources/liquidbounce/lang/zh_cn.json +++ b/src/main/resources/resources/liquidbounce/lang/zh_cn.json @@ -21,7 +21,7 @@ "liquidbounce.command.binds.subcommand.list.result.bindings": "快捷键", "liquidbounce.command.binds.subcommand.list.result.noBindings": "未找到任何快捷键。", "liquidbounce.command.binds.subcommand.list.result.page": "页数: %s", - "liquidbounce.command.binds.subcommand.list.result.pageNumberTooLarge": "你输入的页数过大,一共有 %d 页。", + "liquidbounce.command.binds.subcommand.list.result.pageNumberTooLarge": "你输入的页数过大,一共有 %s 页。", "liquidbounce.command.binds.subcommand.remove.description": "移除快捷键。", "liquidbounce.command.binds.subcommand.remove.parameter.name.description": "模块名。", "liquidbounce.command.binds.subcommand.remove.result.bindRemoved": "已移除模块 \"%s\" 的快捷键。", From 18bdc405d50aa47de4eb6a461c87d04e29963766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:58:24 +0800 Subject: [PATCH 2/3] remove redundant sort --- .../features/command/commands/client/CommandBinds.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt index a2df3dfe84e..ba9910bd4e6 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt @@ -79,8 +79,7 @@ object CommandBinds : CommandFactory { 1 }.coerceAtLeast(1) - val bindings = ModuleManager.sortedBy { it.name } - .filter { !it.bind.isUnbound } + val bindings = ModuleManager.filter { !it.bind.isUnbound } if (bindings.isEmpty()) { throw CommandException(command.result("noBindings")) From 88dcbd3166d99c76f474226083414e4b476ca833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:59:34 +0800 Subject: [PATCH 3/3] change code style --- .../features/command/commands/client/CommandBinds.kt | 6 +----- .../features/command/commands/module/CommandAutoDisable.kt | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt index ba9910bd4e6..01dfd635cc8 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/client/CommandBinds.kt @@ -73,11 +73,7 @@ object CommandBinds : CommandFactory { .build() ) .handler { command, args -> - val page = if (args.isNotEmpty()) { - args[0] as Int - } else { - 1 - }.coerceAtLeast(1) + val page = (args.firstOrNull() as? Int ?: 1).coerceAtLeast(1) val bindings = ModuleManager.filter { !it.bind.isUnbound } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt index de2546192a4..e9f5f661319 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/command/commands/module/CommandAutoDisable.kt @@ -72,11 +72,7 @@ object CommandAutoDisable : CommandFactory { .build() ) .handler { command, args -> - val page = if (args.isNotEmpty()) { - args[0] as Int - } else { - 1 - }.coerceAtLeast(1) + val page = (args.firstOrNull() as? Int ?: 1).coerceAtLeast(1) val modules = ModuleAutoDisable.listOfModules.sortedBy { it.name }