Skip to content

Commit cc01ea3

Browse files
committed
feat(command): add suggestion providers for int, double, boolean, and player inputs
1 parent b11d65c commit cc01ea3

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

common-platform-api/src/main/kotlin/taboolib/common/platform/command/ExtraComponent.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ fun CommandComponent.int(
1616
dynamic: CommandComponentDynamic.() -> Unit = {}
1717
): CommandComponentDynamic {
1818
return dynamic(comment, optional, permission, dynamic).also {
19-
// 如果没有额外建议则约束参数输入
20-
if (suggest.isEmpty()) {
21-
it.restrictInt()
22-
} else {
23-
it.suggestUncheck { suggest }
24-
}
19+
CommandComponent.intSuggestProvider(it, comment, suggest)
2520
}
2621
}
2722

@@ -38,12 +33,7 @@ fun CommandComponent.decimal(
3833
dynamic: CommandComponentDynamic.() -> Unit = {}
3934
): CommandComponentDynamic {
4035
return dynamic(comment, optional, permission, dynamic).also {
41-
// 如果没有额外建议则约束参数输入
42-
if (suggest.isEmpty()) {
43-
it.restrictDouble()
44-
} else {
45-
it.suggestUncheck { suggest }
46-
}
36+
CommandComponent.decimalSuggestProvider(it, comment, suggest)
4737
}
4838
}
4939

@@ -56,7 +46,9 @@ fun CommandComponent.bool(
5646
permission: String = "",
5747
dynamic: CommandComponentDynamic.() -> Unit = {}
5848
): CommandComponentDynamic {
59-
return dynamic(comment, optional, permission, dynamic).suggestBoolean()
49+
return dynamic(comment, optional, permission, dynamic).also {
50+
CommandComponent.boolSuggestProvider(it, comment)
51+
}
6052
}
6153

6254
/**
@@ -71,5 +63,7 @@ fun CommandComponent.player(
7163
permission: String = "",
7264
dynamic: CommandComponentDynamic.() -> Unit = {}
7365
): CommandComponentDynamic {
74-
return dynamic(comment, optional, permission, dynamic).suggestPlayers(suggest)
66+
return dynamic(comment, optional, permission, dynamic).also {
67+
CommandComponent.playerSuggestProvider(it, comment, suggest)
68+
}
7569
}

common-platform-api/src/main/kotlin/taboolib/common/platform/command/component/CommandComponent.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package taboolib.common.platform.command.component
22

33
import taboolib.common.platform.command.CommandContext
4+
import taboolib.common.platform.command.restrictDouble
5+
import taboolib.common.platform.command.restrictInt
6+
import taboolib.common.platform.command.suggestBoolean
7+
import taboolib.common.platform.command.suggestPlayers
8+
import taboolib.common.platform.command.suggestUncheck
49

510
abstract class CommandComponent(val index: Int, var optional: Boolean, val permission: String = "") {
611

@@ -115,4 +120,33 @@ abstract class CommandComponent(val index: Int, var optional: Boolean, val permi
115120
}
116121
}
117122
}
123+
124+
companion object {
125+
126+
var intSuggestProvider: CommandComponentDynamic.(comment: String, suggest: List<String>) -> Unit = { comment, suggest ->
127+
// 如果没有额外建议则约束参数输入
128+
if (suggest.isEmpty()) {
129+
restrictInt()
130+
} else {
131+
suggestUncheck { suggest }
132+
}
133+
}
134+
135+
var decimalSuggestProvider: CommandComponentDynamic.(comment: String, suggest: List<String>) -> Unit = { comment, suggest ->
136+
// 如果没有额外建议则约束参数输入
137+
if (suggest.isEmpty()) {
138+
restrictDouble()
139+
} else {
140+
suggestUncheck { suggest }
141+
}
142+
}
143+
144+
var boolSuggestProvider: CommandComponentDynamic.(comment: String) -> Unit = { comment ->
145+
suggestBoolean()
146+
}
147+
148+
var playerSuggestProvider: CommandComponentDynamic.(comment: String, suggest: List<String>) -> Unit = { comment, suggest ->
149+
suggestPlayers(suggest)
150+
}
151+
}
118152
}

0 commit comments

Comments
 (0)