Skip to content

Commit 3c3d472

Browse files
committed
🚚(wayzer/cmds/voteOb)
1 parent 05628a8 commit 3c3d472

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

scripts/wayzer/cmds/voteOb.kts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
@file:Depends("wayzer/cmds/voteKick", "功能控制,使用util,覆盖votekick")
2+
@file:Depends("wayzer/map/betterTeam", "强制观察者")
3+
4+
package wayzer.cmds
5+
6+
import wayzer.VoteEvent
7+
import wayzer.map.BetterTeam
8+
import java.time.Duration
9+
import java.time.Instant
10+
11+
val teams = contextScript<BetterTeam>()
12+
val voteKick = contextScript<wayzer.cmds.VoteKick>()
13+
14+
@Savable(false)
15+
val limitPlayers = mutableMapOf<String, Pair<String, Instant>>()//profile -> reason,time
16+
customLoad(this::limitPlayers) { limitPlayers.putAll(it) }
17+
18+
onEnable {
19+
val script = this
20+
VoteEvent.VoteCommands += CommandInfo(script, "ob", "强制观战") {
21+
aliases = listOf("观战")
22+
usage = "<玩家名/id> <理由>"
23+
permission = "wayzer.vote.ob"
24+
body {
25+
val target = with(voteKick) { getTarget() }
26+
val reason = with(voteKick) { getInput("限制观战理由", "[red]投票限制他人需要理由".with()) }
27+
val player = player!!
28+
val event = VoteEvent(
29+
script, player,
30+
voteDesc = "强制观战(目标[red]{target.name}[yellow])".with("target" to target),
31+
extDesc = "[red]理由: [yellow]${reason}"
32+
)
33+
val ids = PlayerData[target].ids
34+
if (event.awaitResult()) {
35+
if (target.hasPermission("wayzer.admin.skipKick"))
36+
return@body broadcast(
37+
"[red]错误: {target.name}[red]为管理员, 如有问题请与服主联系".with("target" to target)
38+
)
39+
ids.forEach {
40+
limitPlayers[it] = reason to Instant.now()
41+
}
42+
teams.changeTeam(target, teams.spectateTeam)
43+
broadcast(
44+
"[yellow][提示][green]如目标用户继续捣乱,可以使用[gold]/vote kick {player.shortID}[]投票踢出".with(
45+
"player" to target
46+
)
47+
)
48+
}
49+
}
50+
}
51+
VoteEvent.VoteCommands += CommandInfo(script, "quitOb", "解除强行观战限制(限本人)") {
52+
aliases = listOf("解除观战")
53+
body {
54+
val player = player!!
55+
val id = PlayerData[player].id
56+
val (reason, time) = limitPlayers[id]
57+
?: returnReply("[yellow]你未被限制游戏,无需解除".with())
58+
val delta = Duration.between(time, Instant.now())
59+
val event = VoteEvent(
60+
script, player,
61+
voteDesc = "解除强制(已持续{delta:分钟})".with("delta" to delta),
62+
extDesc = "[yellow]被限制时的理由: $reason"
63+
)
64+
if (event.awaitResult()) {
65+
limitPlayers.remove(id)
66+
teams.changeTeam(player)
67+
}
68+
}
69+
}
70+
}
71+
72+
listenTo<BetterTeam.AssignTeamEvent>(Event.Priority.Intercept) {
73+
limitPlayers[PlayerData[player].id]?.let { (reason, time) ->
74+
val delta = Duration.between(time, Instant.now())
75+
player.sendMessage(
76+
"""
77+
[red]你已被限制强制观战.
78+
[yellow]投票原因: [white]{reason}({delta:分钟}前)
79+
[yellow]如有疑问,请在聊天区交流
80+
[green]可通过[gold]/vote quitOb[]投票,取消限制
81+
""".trimIndent().with("reason" to reason, "delta" to delta),
82+
MsgType.InfoMessage
83+
)
84+
team = teams.spectateTeam
85+
}
86+
}
87+
command("votekick", "(弃用)投票踢人") {
88+
this.usage = "<player...>";this.type = CommandType.Client
89+
body {
90+
//Redirect
91+
arg = listOf("ob", *arg.toTypedArray())
92+
VoteEvent.VoteCommands.handle()
93+
}
94+
}
95+
command("forceOB", "管理指令:使某人强制观战") {
96+
usage = "<玩家名/id>"
97+
permission = "wayzer.admin.forceOb"
98+
body {
99+
val target = with(voteKick) { getTarget() }
100+
val id = PlayerData[target].id
101+
if (id in limitPlayers) {
102+
limitPlayers.remove(id)
103+
teams.changeTeam(target)
104+
returnReply("[green]已解除目标限制".with())
105+
}
106+
val reason = with(voteKick) { getInput("限制观战理由", "[red]投票限制他人需要理由".with()) }
107+
limitPlayers[id] = reason to Instant.now()
108+
teams.changeTeam(target, teams.spectateTeam)
109+
broadcast(
110+
"[red] 管理员强制{target.name}[red]成为观察者,原因: [yellow]{reason}"
111+
.with("target" to target, "reason" to reason)
112+
)
113+
}
114+
}
115+
PermissionApi.registerDefault("wayzer.admin.skipKick", "wayzer.admin.forceOb", group = "@admin")

0 commit comments

Comments
 (0)