Skip to content

Commit 8497182

Browse files
committed
Command Action Support Folia
1 parent b2623dd commit 8497182

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

api/action/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ dependencies {
22
api(project(":common"))
33

44
compileOnly("net.md-5:bungeecord-chat:1.18-R0.1-SNAPSHOT")
5+
6+
7+
// Folia
8+
compileOnly("io.paper:folia-api:1.20.4")
9+
510
}
611

712
taboolib { subproject = true }

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package trplugins.menu.api.action.impl.send
22

33
import taboolib.common.platform.ProxyPlayer
44
import taboolib.common.platform.function.submit
5+
import taboolib.platform.Folia
56
import trplugins.menu.api.action.ActionHandle
67
import trplugins.menu.api.action.base.ActionBase
78
import trplugins.menu.api.action.base.ActionContents
9+
import trplugins.menu.api.utils.FoliaUtil
810

911
/**
1012
* TrMenu
@@ -19,8 +21,13 @@ class Command(handle: ActionHandle) : ActionBase(handle) {
1921

2022
override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) {
2123
placeholderPlayer.parseContentSplited(contents.stringContent(), ";").forEach {
22-
submit(async = false) {
23-
player.performCommand(it)
24+
// Folia 必须使用实体调度器 暂时不做优雅的兼容性处理 后期其他功能需要单独处理Folia时再修改
25+
if (Folia.isFolia) {
26+
FoliaUtil.invokeCommandWithEntityScheduler(player,it)
27+
}else{
28+
submit(async = false) {
29+
player.performCommand(it)
30+
}
2431
}
2532
}
2633
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package trplugins.menu.api.utils
2+
3+
import io.papermc.paper.threadedregions.scheduler.EntityScheduler
4+
import taboolib.common.platform.ProxyPlayer
5+
import taboolib.library.reflex.Reflex.Companion.invokeMethod
6+
import taboolib.platform.BukkitPlugin
7+
8+
/**
9+
* @author 大阔
10+
* @since 2025/1/25 00:16
11+
*/
12+
object FoliaUtil {
13+
14+
fun invokeCommandWithEntityScheduler(player: ProxyPlayer,command:String){
15+
getEntityScheduler(player).execute(BukkitPlugin.getInstance(),{
16+
player.performCommand(command)
17+
},null,0)
18+
}
19+
20+
fun getEntityScheduler(player: ProxyPlayer): EntityScheduler {
21+
return player.cast<Any>().invokeMethod<EntityScheduler>("getScheduler")!!
22+
}
23+
24+
}

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.3.7
2+
version=3.3.8

plugin/src/main/resources/lang/zh_CN.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Plugin-Update:
88
- '&bhttps://www.spigotmc.org/resources/83120/'
99
Plugin-Version:
1010
- '&8[&3Tr&bMenu&8] &b版本 &8| &3你正在使用社区维护版本:'
11-
- '&bhttps://github.com/Dreeam-qwq/TrMenu'
11+
- '&bhttps://github.com/Coderkuo/TrMenu'
1212
Plugin-Dependency-Hooked: '&8[&3Tr&bMenu&8] &6挂钩 &8| &7软依赖 &f{0} &7已兼容.'
1313
Plugin-Dependency-Abuse: '&8[&3Tr&bMenu&8] &6挂钩 &8| &4试图使用未挂钩插件 &c{0}'
1414

0 commit comments

Comments
 (0)