Skip to content

Commit f1d2345

Browse files
committed
[2.3.3] 更全面的玩家消息处理方式
* 兼容CraftEngine表情 * ItemShow 支持组件item_name * TrChatEvent 支持编辑component * /trchat tellsimple 支持跨服 * GitHub Actions新增api版本
1 parent c0dd49c commit f1d2345

File tree

30 files changed

+257
-117
lines changed

30 files changed

+257
-117
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
run: chmod +x ./gradlew
2727
- name: build
2828
run: ./gradlew build
29+
- name: build api
30+
run: ./gradlew taboolibBuildApi -PDeleteCode
2931
- name: capture build artifacts
3032
uses: actions/upload-artifact@v4
3133
with:

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ subprojects {
3535
)
3636
install(JavaScript)
3737
install(Bukkit, BungeeCord, Velocity)
38+
modules.remove("minecraft-chat")
3839
}
3940
version {
4041
taboolib = "6.2.3-b217935"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=me.arasple.mc.trchat
2-
version=2.3.2
2+
version=2.3.3
33
kotlin.incremental=true
44
kotlin.incremental.java=true
55
kotlin.incremental.useClasspathSnapshot=true
-1.7 MB
Binary file not shown.
2.52 MB
Binary file not shown.

project/module-adventure/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dependencies {
22
compileOnly(project(":project:common"))
33
compileOnly(project(":project:module-chat"))
44
compileOnly("net.kyori:adventure-platform-bukkit:4.4.0")
5+
compileOnly("net.kyori:adventure-text-serializer-plain:4.21.0")
56
// paper native
67
compileOnly(fileTree(rootDir.resolve("libs")))
78
}

project/module-adventure/src/main/kotlin/me/arasple/mc/trchat/module/adventure/Adventure.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package me.arasple.mc.trchat.module.adventure
33
import net.kyori.adventure.text.Component
44
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
55
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
6+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
67
import org.bukkit.inventory.ItemStack
78
import taboolib.module.chat.ComponentText
9+
import taboolib.module.chat.Components
810
import taboolib.module.chat.impl.AdventureComponent
911

1012
private val legacySerializer: Any? = try {
@@ -19,13 +21,26 @@ private val gsonSerializer: Any? = try {
1921
null
2022
}
2123

24+
private val plainSerializer: Any? = try {
25+
PlainTextComponentSerializer.plainText()
26+
} catch (_: Throwable) {
27+
null
28+
}
29+
2230
fun gson(component: Component) = (gsonSerializer as GsonComponentSerializer).serialize(component)
2331

2432
fun gson(string: String) = (gsonSerializer as GsonComponentSerializer).deserialize(string)
2533

34+
fun Component.toPlain() = (plainSerializer as PlainTextComponentSerializer).serialize(this)
35+
2636
fun ComponentText.toAdventure(): Component {
27-
if (this is AdventureComponent) return this.component
28-
else return gson(this.toRawMessage())
37+
return if (this is AdventureComponent) this.component
38+
else gson(this.toRawMessage())
39+
}
40+
41+
fun Component.toNative(): ComponentText {
42+
return if (Components.useAdventure) AdventureComponent(this)
43+
else Components.parseRaw(gson(this))
2944
}
3045

3146
fun ComponentText.hoverItemAdventure(item: ItemStack): ComponentText {

project/module-chat/src/main/kotlin/taboolib/module/chat/Source.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package taboolib.module.chat
22

3+
import net.kyori.adventure.text.Component
34
import net.md_5.bungee.api.chat.BaseComponent
45
import taboolib.common.platform.ProxyCommandSender
56

@@ -24,6 +25,9 @@ interface Source {
2425
/** 转换为 Spigot 对象 */
2526
fun toSpigotObject(): BaseComponent
2627

28+
/** 转换为 Adventure 对象 */
29+
fun toAdventureObject(): Component
30+
2731
/** 转换为 RawMessage */
2832
fun toLegacyRawMessage(): RawMessage
2933

project/module-chat/src/main/kotlin/taboolib/module/chat/impl/AdventureComponent.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ class AdventureComponent() : ComponentText {
303303
return net.md_5.bungee.api.chat.TextComponent(*ComponentSerializer.parse(toRawMessage()))
304304
}
305305

306+
override fun toAdventureObject(): Component {
307+
return component
308+
}
309+
306310
override fun toLegacyRawMessage(): RawMessage {
307311
return RawMessage(this)
308312
}

project/module-chat/src/main/kotlin/taboolib/module/chat/impl/DefaultComponent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package taboolib.module.chat.impl
22

3+
import net.kyori.adventure.text.Component
34
import net.md_5.bungee.api.ChatColor
45
import net.md_5.bungee.api.chat.*
56
import net.md_5.bungee.api.chat.hover.content.Entity
@@ -335,6 +336,10 @@ class DefaultComponent() : ComponentText {
335336
return component
336337
}
337338

339+
override fun toAdventureObject(): Component {
340+
TODO("Unsupported")
341+
}
342+
338343
override fun toLegacyRawMessage(): RawMessage {
339344
return RawMessage(this)
340345
}

0 commit comments

Comments
 (0)