Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ subprojects {
disableOnSkippedVersion = false
}
version {
taboolib = "6.2.4-abd325ee"
taboolib = "6.2.4-65252583"
coroutines = null
}
}
Expand Down
7 changes: 6 additions & 1 deletion common/src/main/kotlin/trplugins/menu/util/conf/Property.kt
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ enum class Property(val default: String, val regex: Regex) {
/**
* 菜单内置国际化
*/
LANG("Lang", "lang(uage)?|internationalization|i18n");
LANG("Lang", "lang(uage)?|internationalization|i18n"),

/**
* 菜单内虚拟OP命令
*/
COMMAND_FAKE_OP("Command-Fake-Op", "command-?fake-?op");

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

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=me.arasple.mc.trmenu
version=3.9.12
version=3.9.14
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import taboolib.expansion.dispatchCommandAsOp
import trplugins.menu.api.action.ActionHandle
import trplugins.menu.api.action.base.ActionBase
import trplugins.menu.api.action.base.ActionContents
import trplugins.menu.module.display.session

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

override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) {
val fakeOp = player.session().menu?.settings?.commandFakeOp ?: true
contents.stringContent().parseContentSplited(placeholderPlayer, ";").forEach {
submit(async = false) {
player.cast<Player>().dispatchCommandAsOp(it)
if (fakeOp) {
player.cast<Player>().dispatchCommandAsOp(it)
} else {
player.isOp.let { isOp ->
player.isOp = true
try {
player.performCommand(it)
} catch (e: Throwable) {
e.printStackTrace()
} finally {
player.isOp = isOp
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ object MenuSerializer : ISerializer {
val eventOpen = Property.EVENT_OPEN.ofList(events)
val eventClose = Property.EVENT_CLOSE.ofList(events)
val eventClick = Property.EVENT_CLICK.ofList(events)
val commandFakeOp = Property.COMMAND_FAKE_OP.ofBoolean(options, true)

val settings = MenuSettings(
CycleList(title),
Expand Down Expand Up @@ -199,7 +200,8 @@ object MenuSerializer : ISerializer {
)
}
},
funs.map { ScriptFunction(it.key, it.value.toString()) }.toSet()
funs.map { ScriptFunction(it.key, it.value.toString()) }.toSet(),
commandFakeOp
)

// i18n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class MenuSettings(
val closeEvent: Reactions,
val clickEvent: Reactions,
val tasks: List<MenuTaskData>,
val internalFunctions: Set<ScriptFunction>
val internalFunctions: Set<ScriptFunction>,
val commandFakeOp: Boolean = true,
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package trplugins.menu.module.internal.service

import org.bukkit.Bukkit
import org.bukkit.entity.Player
import taboolib.common.platform.command.PermissionDefault
import taboolib.common.platform.command.command
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.submit
import taboolib.common.platform.function.unregisterCommand
import trplugins.menu.TrMenu
import trplugins.menu.TrMenu.actionHandle
Expand All @@ -24,9 +26,12 @@ object RegisterCommands {
}

fun load() {
registered.removeIf {
unregisterCommand(it)
true
submit {
registered.removeIf {
unregisterCommand(it)
true
}

}

TrMenu.SETTINGS.getConfigurationSection("RegisterCommands")?.let { it ->
Expand Down Expand Up @@ -72,6 +77,13 @@ object RegisterCommands {
}
}
}
}

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