Skip to content

Commit db7169f

Browse files
authored
Merge pull request #239 from YsGqHY/stable/v3
feat: 修复settings配置重载时报错 & 添加虚拟OP命令执行选项
2 parents 79fc4e5 + 68e71b7 commit db7169f

7 files changed

Lines changed: 45 additions & 10 deletions

File tree

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.12
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 {

plugin/src/main/kotlin/trplugins/menu/module/internal/service/RegisterCommands.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package trplugins.menu.module.internal.service
22

3+
import org.bukkit.Bukkit
34
import org.bukkit.entity.Player
45
import taboolib.common.platform.command.PermissionDefault
56
import taboolib.common.platform.command.command
67
import taboolib.common.platform.function.adaptPlayer
8+
import taboolib.common.platform.function.submit
79
import taboolib.common.platform.function.unregisterCommand
810
import trplugins.menu.TrMenu
911
import trplugins.menu.TrMenu.actionHandle
@@ -24,9 +26,12 @@ object RegisterCommands {
2426
}
2527

2628
fun load() {
27-
registered.removeIf {
28-
unregisterCommand(it)
29-
true
29+
submit {
30+
registered.removeIf {
31+
unregisterCommand(it)
32+
true
33+
}
34+
3035
}
3136

3237
TrMenu.SETTINGS.getConfigurationSection("RegisterCommands")?.let { it ->
@@ -72,6 +77,13 @@ object RegisterCommands {
7277
}
7378
}
7479
}
75-
}
7680

81+
// 延迟同步命令到所有在线玩家,避免与 Paper 异步命令发送线程冲突
82+
// Paper 的 sendAsync 会在异步线程遍历命令树,直接调用 updateCommands 可能触发 ConcurrentModificationException
83+
submit(delay = 1) {
84+
try {
85+
Bukkit.getOnlinePlayers().forEach { it.updateCommands() }
86+
} catch (_: Throwable) {}
87+
}
88+
}
7789
}

0 commit comments

Comments
 (0)