Skip to content

Commit ae9b39a

Browse files
committed
[Update](*) 更新适配新版CommandApi
1 parent 342466a commit ae9b39a

File tree

7 files changed

+40
-46
lines changed

7 files changed

+40
-46
lines changed

src/coreLibrary/controlCommand.content.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ onEnable {
5454
addSub(CommandInfo(thisRef, "reload", "重载一个脚本或者模块") {
5555
usage = "<module[/script]>"
5656
permission = "scriptAgent.control.reload"
57-
onComplete = {
57+
onComplete {
5858
onComplete(0) {
5959
(arg[0].split('/')[0].let(ScriptManager::getScript)?.let { it as IInitScript }?.children
6060
?: ScriptManager.loadedInitScripts.values).map { it.id }
6161
}
6262
}
63-
body = body@{
64-
if (arg.isEmpty()) return@body replyUsage()
63+
body {
64+
if (arg.isEmpty()) replyUsage()
6565
GlobalScope.launch {
6666
reply("[yellow]异步处理中".with())
6767
val success: Boolean = when (val script = arg.getOrNull(0)?.let(ScriptManager::getScript)) {
@@ -80,7 +80,7 @@ onEnable {
8080
usage = "<filePath>"
8181
aliases = listOf("load")
8282
permission = "scriptAgent.control.load"
83-
body = body@{
83+
body {
8484
val file = arg.getOrNull(0)?.let(Config.rootDir::resolve)
8585
?: return@body reply("[red]未找到对应文件".with())
8686
GlobalScope.launch {

src/coreMindustry/lib/ContentExt.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fun IContentScript.command(
5656
}
5757

5858
@Deprecated("use new command api", ReplaceWith("command(name,description){init();body(handler)}"))
59-
fun IContentScript.command(name: String, description: String, init: CommandInfo.() -> Unit = {}, handler: CommandHandler) {
59+
fun IContentScript.command(name: String, description: String, init: CommandInfo.() -> Unit, handler: CommandHandler) {
6060
RootCommands += CommandInfo(this, name, description) {
6161
init()
6262
body(handler)

src/main/helpfulCommand.content.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package main
22

33
import arc.graphics.Colors
44

5-
command("showColor", "显示所有颜色") {
5+
command("showColor", "显示所有颜色", {}) {
66
reply(Colors.getColors().joinToString("[],") { "[#${it.value}]${it.key}" }.with())
77
}

src/mirai.init.kts

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ onEnable {
6262
}
6363

6464
Commands.controlCommand.let {
65-
it += CommandInfo(this, "mirai", "重定向输入到mirai", {
65+
it += CommandInfo(this, "mirai", "重定向输入到mirai") {
6666
usage = "[args...]"
6767
permission = "mirai.input"
68-
}) {
69-
channel.sendBlocking(this.arg.joinToString(" "))
68+
body {
69+
channel.sendBlocking(arg.joinToString(" "))
70+
}
7071
}
7172
}

src/wayzer/admin.content.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ val Admin = Admin()
1818

1919
inner class Admin : SharedData.IAdmin {
2020
override fun isAdmin(player: Player): Boolean {
21-
return player.isAdmin||admins.contains(player.uuid)
21+
return player.isAdmin || admins.contains(player.uuid)
2222
}
2323

2424
override fun ban(player: Player, uuid: String) {
@@ -41,7 +41,7 @@ listen<EventType.PlayerBanEvent> {
4141
it.player?.con?.kick(Packets.KickReason.banned)
4242
}
4343

44-
command("list", "列出当前玩家") {
44+
command("list", "列出当前玩家", {}) {
4545
val list = playerGroup.all().map {
4646
"{player.name}[white]([red]{player.shortID}[white]) ".with("player" to it)
4747
}

src/wayzer/ext/vote.content.kts

+5-3
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ command("vote", "发起投票", {
5151
}, voteCommands)
5252
command("votekick", "(弃用)投票踢人", { this.usage = "<player...>";this.type = CommandType.Client }) {
5353
//Redirect
54-
voteCommands.invoke(new { arg = listOf("kick", *arg.toTypedArray()) })
54+
arg = listOf("kick", *arg.toTypedArray())
55+
voteCommands.invoke(this)
5556
}
5657

5758
export(::voteCommands)
5859

5960
fun subVote(desc: String, usage: String, vararg aliases: String, body: CommandContext.() -> Unit) {
60-
voteCommands += CommandInfo(null, aliases.first(), desc, {
61+
voteCommands += CommandInfo(null, aliases.first(), desc) {
6162
this.usage = usage
6263
this.aliases = aliases.toList()
63-
}, body)
64+
body(body)
65+
}
6466
}
6567

6668
class NetFi(private val url: URL, file: String) : Fi(file) {

src/wayzer/user/skills.content.kts

+23-32
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,38 @@ listen<EventType.ResetEvent> {
1414
used.clear()
1515
}
1616

17-
fun skill(name: String, desc: String, vararg aliases: String, body: CommandContext.() -> Unit) {
18-
command(name, desc, {
19-
permission = "wayzer.user.skills.$name"
20-
this.aliases = aliases.toList()
21-
type = CommandType.Client
22-
}, body)
23-
}
24-
2517
/**
2618
* @param coolDown in ms; <0 ->一局冷却
2719
*/
28-
fun CommandContext.checkBefore(allowPvp: Boolean, coolDown: Int?) {
29-
if (state.rules.mode() !in arrayOf(Gamemode.survival, Gamemode.attack) && (!allowPvp || state.rules.pvp)) {
30-
reply("[red]当前模式禁用".with())
31-
CommandInfo.Return()
32-
}
33-
if (player!!.dead) {
34-
reply("[red]你已死亡".with())
35-
CommandInfo.Return()
36-
}
37-
if (coolDown != null) {
38-
val id = PlayerData[player!!.uuid].profile?.id?.value ?: 0
39-
val key = "${thisCommand.name}@$id"
40-
if (key in used) {
41-
if (coolDown < 0) {
42-
reply("[red]该技能每局限用一次".with())
43-
CommandInfo.Return()
44-
} else if (used[key]!! >= System.currentTimeMillis()) {
45-
reply("[red]技能冷却,还剩{time:秒}".with("time" to Duration.ofMillis(used[key]!! - System.currentTimeMillis())))
46-
CommandInfo.Return()
20+
fun skill(name: String, desc: String, allowPvp: Boolean, coolDown: Int?, vararg aliases: String, body: CommandContext.() -> Unit) {
21+
command(name, desc) {
22+
permission = "wayzer.user.skills.$name"
23+
this.aliases = aliases.toList()
24+
type = CommandType.Client
25+
body {
26+
if (state.rules.mode() !in arrayOf(Gamemode.survival, Gamemode.attack) && (!allowPvp || state.rules.pvp))
27+
returnReply("[red]当前模式禁用".with())
28+
if (player!!.dead)
29+
returnReply("[red]你已死亡".with())
30+
if (coolDown != null) {
31+
val id = PlayerData[player!!.uuid].profile?.id?.value ?: 0
32+
val key = "${name}@$id"
33+
if (key in used) {
34+
if (coolDown < 0)
35+
returnReply("[red]该技能每局限用一次".with())
36+
else if (used[key]!! >= System.currentTimeMillis())
37+
returnReply("[red]技能冷却,还剩{time:秒}".with("time" to Duration.ofMillis(used[key]!! - System.currentTimeMillis())))
38+
}
39+
used[key] = System.currentTimeMillis() + coolDown
4740
}
41+
body(body)
4842
}
49-
used[key] = System.currentTimeMillis() + coolDown
5043
}
5144
}
5245

5346
fun Player.broadcastSkill(skill: String) = broadcast("[yellow][技能][green]{player.name}[white]使用了[green]{skill}[white]技能.".with("player" to this, "skill" to skill), quite = true)
5447

55-
skill("draug", "技能: 召唤采矿机,一局限一次,PVP禁用", "矿机") {
56-
checkBefore(false, -1)
48+
skill("draug", "技能: 召唤采矿机,一局限一次,PVP禁用", false, -1, "矿机") {
5749
if (state.rules.bannedBlocks.contains(Blocks.draugFactory))
5850
return@skill reply("[red]该地图采矿机已禁封,禁止召唤".with())
5951
UnitTypes.draug.create(player!!.team).apply {
@@ -63,8 +55,7 @@ skill("draug", "技能: 召唤采矿机,一局限一次,PVP禁用", "矿机") {
6355
player!!.broadcastSkill("召唤采矿机")
6456
}
6557

66-
skill("noFire", "技能: 灭火,半径10格,冷却120s", "灭火") {
67-
checkBefore(false, 120_000)
58+
skill("noFire", "技能: 灭火,半径10格,冷却120s", false, 120_000, "灭火") {
6859
fireGroup.forEach {
6960
if (it.dst(player!!) <= 80)
7061
it.remove()

0 commit comments

Comments
 (0)