Skip to content

Commit 7623ad2

Browse files
committed
feat(menu): 添加虚拟OP命令执行选项
- 新增配置项 COMMAND_FAKE_OP 控制是否使用虚拟OP执行命令 - 在 CommandOp 动作中实现真实OP权限切换逻辑 - 更新菜单序列化器以支持新的命令执行配置 - 升级 TabooLib 版本依赖 - 增加插件版本号至 3.9.14
1 parent b65049d commit 7623ad2

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ subprojects {
7272
disableOnSkippedVersion = false
7373
}
7474
version {
75-
taboolib = "6.2.4-abd325ee"
75+
taboolib = "6.2.4-65252583"
7676
coroutines = null
7777
}
7878
}

common/src/main/kotlin/trplugins/menu/util/conf/Property.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ enum class Property(val default: String, val regex: Regex) {
271271
/**
272272
* 菜单内置国际化
273273
*/
274-
LANG("Lang", "lang(uage)?|internationalization|i18n");
274+
LANG("Lang", "lang(uage)?|internationalization|i18n"),
275+
276+
/**
277+
* 菜单内虚拟OP命令
278+
*/
279+
COMMAND_FAKE_OP("Command-Fake-Op", "command-?fake_?op");
275280

276281
constructor(default: String, regex: String) : this(default, Regex("(?i)$regex"))
277282

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group=me.arasple.mc.trmenu
2-
version=3.9.13
2+
version=3.9.14

plugin/src/main/kotlin/trplugins/menu/api/action/impl/send/CommandOp.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import taboolib.expansion.dispatchCommandAsOp
77
import trplugins.menu.api.action.ActionHandle
88
import trplugins.menu.api.action.base.ActionBase
99
import trplugins.menu.api.action.base.ActionContents
10+
import trplugins.menu.module.display.session
1011

1112
/**
1213
* TrMenu
@@ -20,9 +21,23 @@ class CommandOp(handle: ActionHandle) : ActionBase(handle) {
2021
override val regex = "op(erator)?s?".toRegex()
2122

2223
override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) {
24+
val fakeOp = player.session().menu?.settings?.commandFakeOp ?: true
2325
contents.stringContent().parseContentSplited(placeholderPlayer, ";").forEach {
2426
submit(async = false) {
25-
player.cast<Player>().dispatchCommandAsOp(it)
27+
if (fakeOp) {
28+
player.cast<Player>().dispatchCommandAsOp(it)
29+
} else {
30+
player.isOp.let { isOp ->
31+
player.isOp = true
32+
try {
33+
player.performCommand(it)
34+
} catch (e: Throwable) {
35+
e.printStackTrace()
36+
} finally {
37+
player.isOp = isOp
38+
}
39+
}
40+
}
2641
}
2742
}
2843
}

plugin/src/main/kotlin/trplugins/menu/module/conf/MenuSerializer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ object MenuSerializer : ISerializer {
168168
val eventOpen = Property.EVENT_OPEN.ofList(events)
169169
val eventClose = Property.EVENT_CLOSE.ofList(events)
170170
val eventClick = Property.EVENT_CLICK.ofList(events)
171+
val commandFakeOp = Property.COMMAND_FAKE_OP.ofBoolean(options, true)
171172

172173
val settings = MenuSettings(
173174
CycleList(title),
@@ -199,7 +200,8 @@ object MenuSerializer : ISerializer {
199200
)
200201
}
201202
},
202-
funs.map { ScriptFunction(it.key, it.value.toString()) }.toSet()
203+
funs.map { ScriptFunction(it.key, it.value.toString()) }.toSet(),
204+
commandFakeOp
203205
)
204206

205207
// i18n

plugin/src/main/kotlin/trplugins/menu/module/display/MenuSettings.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class MenuSettings(
3333
val closeEvent: Reactions,
3434
val clickEvent: Reactions,
3535
val tasks: List<MenuTaskData>,
36-
val internalFunctions: Set<ScriptFunction>
36+
val internalFunctions: Set<ScriptFunction>,
37+
val commandFakeOp: Boolean = true,
3738
) {
3839

3940
companion object {

0 commit comments

Comments
 (0)