Skip to content

Commit a698c6e

Browse files
committed
[2.2.0-beta5] Fix ?
1 parent ded73b5 commit a698c6e

File tree

11 files changed

+69
-99
lines changed

11 files changed

+69
-99
lines changed

build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ subprojects {
3737
install(Bukkit, BungeeCord, Velocity)
3838
}
3939
version {
40-
taboolib = "6.2.0-beta11"
40+
taboolib = "6.2.0-beta16"
4141
coroutines = null
4242
// isSkipKotlin = true
4343
// isSkipKotlinRelocate = true
@@ -61,7 +61,7 @@ subprojects {
6161
compileOnly(kotlin("stdlib"))
6262
compileOnly("com.google.code.gson:gson:2.8.5")
6363
compileOnly("com.google.guava:guava:21.0")
64-
compileOnly("net.kyori:adventure-api:4.16.0")
64+
compileOnly("net.kyori:adventure-api:4.17.0")
6565
}
6666

6767
// 编译配置
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

project/module-adventure/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dependencies {
22
compileOnly(project(":project:common"))
33
compileOnly(project(":project:module-nms"))
4-
compileOnly("net.kyori:adventure-platform-bukkit:4.3.2")
4+
compileOnly("net.kyori:adventure-platform-bukkit:4.3.4")
55
compileOnly(fileTree(rootDir.resolve("libs")))
66
}
77

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package me.arasple.mc.trchat.module.adventure
22

3-
import me.arasple.mc.trchat.api.nms.NMS
43
import net.kyori.adventure.text.Component
54
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
65
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
76
import org.bukkit.inventory.ItemStack
8-
import taboolib.library.reflex.Reflex.Companion.invokeMethod
97
import taboolib.module.chat.ComponentText
108
import taboolib.module.chat.Components
11-
import taboolib.module.nms.Packet
129

1310
private val legacySerializer: Any? = try {
1411
LegacyComponentSerializer.legacySection()
@@ -30,24 +27,6 @@ fun Component.toNative() = Components.parseRaw(gson(this))
3027

3128
fun ComponentText.toAdventure() = gson(toRawMessage())
3229

33-
fun ItemStack.toTranslatableComponentAdventure(): ComponentText {
34-
return Component.translatable(this).toNative()
35-
}
36-
3730
fun ComponentText.hoverItemAdventure(item: ItemStack): ComponentText {
3831
return toAdventure().hoverEvent(item).toNative()
39-
}
40-
41-
fun Packet.getComponent(): ComponentText? {
42-
return when (name) {
43-
"ClientboundSystemChatPacket" -> {
44-
val iChat = source.invokeMethod<Any>("a", findToParent = false, remap = false) ?: return null
45-
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
46-
}
47-
"PacketPlayOutChat" -> {
48-
val iChat = read<Any>("a") ?: return null
49-
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
50-
}
51-
else -> error("Unsupported packet $name")
52-
}
5332
}

project/module-nms/src/main/kotlin/me/arasple/mc/trchat/api/nms/NMS.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ abstract class NMS {
3434
@JvmStatic
3535
val instance by unsafeLazy {
3636
if (MinecraftVersion.majorLegacy < 12005) nmsProxy<NMS>()
37-
else nmsProxy<NMS>("me.arasple.mc.trchat.api.nms.NMSImpl12100")
37+
else nmsProxy<NMS>("me.arasple.mc.trchat.api.nms.NMSImpl12005")
3838
}
3939

40+
// 1.20.4-
4041
val whitelistTags = arrayOf(
4142
// 附魔
4243
"ench",

project/module-nms/src/main/kotlin/me/arasple/mc/trchat/api/nms/NMSImpl12100.kt project/module-nms/src/main/kotlin/me/arasple/mc/trchat/api/nms/NMSImpl12005.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package me.arasple.mc.trchat.api.nms
22

3+
import me.arasple.mc.trchat.util.ServerUtil
34
import net.minecraft.network.chat.IChatBaseComponent
5+
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer
46
import org.bukkit.craftbukkit.v1_20_R3.util.CraftChatMessage
57
import org.bukkit.entity.Player
68
import org.bukkit.inventory.ItemStack
79
import taboolib.common.platform.function.adaptPlayer
810
import taboolib.module.chat.ComponentText
911
import taboolib.module.nms.MinecraftLanguage
1012
import taboolib.module.nms.getLanguageKey
13+
import taboolib.platform.Folia
1114
import taboolib.platform.util.hoverItem
1215
import java.util.*
1316

14-
class NMSImpl12100 : NMS() {
17+
class NMSImpl12005 : NMS() {
1518

1619
override fun craftChatMessageFromComponent(component: ComponentText): Any {
1720
return CraftChatMessage.fromJSON(component.toRawMessage())
@@ -22,7 +25,12 @@ class NMSImpl12100 : NMS() {
2225
}
2326

2427
override fun sendMessage(receiver: Player, component: ComponentText, sender: UUID?, usePacket: Boolean) {
25-
component.sendTo(adaptPlayer(receiver))
28+
if (!usePacket || Folia.isFolia || ServerUtil.isModdedServer) {
29+
component.sendTo(adaptPlayer(receiver))
30+
return
31+
}
32+
val player = (receiver as CraftPlayer).handle
33+
player.sendSystemMessage(craftChatMessageFromComponent(component) as IChatBaseComponent)
2634
}
2735

2836
override fun hoverItem(component: ComponentText, itemStack: ItemStack): ComponentText {

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/ChatSession.kt

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package me.arasple.mc.trchat.module.display
22

3-
import me.arasple.mc.trchat.module.adventure.getComponent
3+
import me.arasple.mc.trchat.api.nms.NMS
44
import me.arasple.mc.trchat.module.conf.file.Settings
55
import me.arasple.mc.trchat.module.display.channel.Channel
66
import me.arasple.mc.trchat.module.display.channel.PrivateChannel
@@ -9,6 +9,9 @@ import me.arasple.mc.trchat.util.color.MessageColors
99
import me.arasple.mc.trchat.util.data
1010
import org.bukkit.entity.Player
1111
import taboolib.expansion.getDataContainer
12+
import taboolib.library.reflex.Reflex.Companion.getProperty
13+
import taboolib.module.chat.ComponentText
14+
import taboolib.module.chat.Components
1215
import taboolib.module.nms.Packet
1316
import taboolib.module.nms.sendPacket
1417
import java.util.*
@@ -109,6 +112,20 @@ class ChatSession(val player: Player) {
109112
sessions -= player.uniqueId
110113
}
111114

115+
private fun Packet.getComponent(): ComponentText? {
116+
return when (name) {
117+
"ClientboundSystemChatPacket" -> {
118+
val iChat = source.getProperty<Any>("content", findToParent = false) ?: return null
119+
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
120+
}
121+
"PacketPlayOutChat" -> {
122+
val iChat = read<Any>("a") ?: return null
123+
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
124+
}
125+
else -> error("Unsupported packet $name")
126+
}
127+
}
128+
112129
data class ChatMessage(val packet: Any, val message: String?)
113130
}
114131
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/format/obj/Text.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Text(val content: String, val condition: Condition?) {
3232
text = HookPlugin.getItemsAdder().replaceFontImages(text, null)
3333
}
3434
return if (isDragonCoreHooked) {
35-
DefaultComponent(listOf(TextComponent(text.replaceWithOrder(*vars).colorify())))
35+
// 使有效部分在latest
36+
Components.empty().append(DefaultComponent(listOf(TextComponent(text.replaceWithOrder(*vars).colorify()))))
3637
} else {
3738
Components.text(text.replaceWithOrder(*vars).colorify())
3839
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt

+29-25
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ import com.google.common.cache.CacheBuilder
55
import me.arasple.mc.trchat.api.event.TrChatItemShowEvent
66
import me.arasple.mc.trchat.api.impl.BukkitProxyManager
77
import me.arasple.mc.trchat.api.nms.NMS
8-
import me.arasple.mc.trchat.module.adventure.toNative
9-
import me.arasple.mc.trchat.module.adventure.toTranslatableComponentAdventure
108
import me.arasple.mc.trchat.module.conf.file.Functions
119
import me.arasple.mc.trchat.module.display.function.Function
1210
import me.arasple.mc.trchat.module.display.function.StandardFunction
1311
import me.arasple.mc.trchat.module.internal.hook.HookPlugin
1412
import me.arasple.mc.trchat.module.internal.hook.type.HookDisplayItem
1513
import me.arasple.mc.trchat.module.internal.script.Reaction
1614
import me.arasple.mc.trchat.util.*
15+
import net.kyori.adventure.translation.Translatable
1716
import org.bukkit.Material
1817
import org.bukkit.block.ShulkerBox
1918
import org.bukkit.entity.Player
2019
import org.bukkit.inventory.Inventory
2120
import org.bukkit.inventory.ItemStack
2221
import org.bukkit.inventory.meta.BlockStateMeta
23-
import taboolib.common.UnsupportedVersionException
2422
import taboolib.common.io.digest
2523
import taboolib.common.platform.Platform
2624
import taboolib.common.platform.PlatformSide
25+
import taboolib.common.platform.function.info
2726
import taboolib.common.util.asList
2827
import taboolib.common.util.replaceWithOrder
2928
import taboolib.common.util.resettableLazy
@@ -37,7 +36,6 @@ import taboolib.module.configuration.ConfigNode
3736
import taboolib.module.configuration.ConfigNodeTransfer
3837
import taboolib.module.nms.MinecraftVersion
3938
import taboolib.module.nms.getI18nName
40-
import taboolib.module.nms.getKey
4139
import taboolib.module.nms.getLanguageKey
4240
import taboolib.module.ui.buildMenu
4341
import taboolib.module.ui.type.Chest
@@ -140,6 +138,7 @@ object ItemShow : Function("ITEM") {
140138
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount, sha1))
141139
}
142140
component.applyStyle(type, part, i, proxySender, newItem.amount, sha1).hoverItemFixed(newItem)
141+
.also { info("$i: ${it.toRawMessage()}") }
143142
}
144143
} else {
145144
sender.getComponentFromLang("Function-Item-Show-Format-New", newItem.amount) { type, i, part, proxySender ->
@@ -206,37 +205,42 @@ object ItemShow : Function("ITEM") {
206205

207206
@Suppress("Deprecation")
208207
private fun ItemStack.getNameComponent(player: Player): ComponentText {
209-
return if (!originName && itemMeta?.hasDisplayName() == true) {
208+
if (!originName && itemMeta?.hasDisplayName() == true) {
209+
// try {
210+
// return itemMeta!!.displayName()!!.toNative()
211+
// } catch (_: Throwable) {
212+
// }
210213
try {
211-
Components.empty().append(itemMeta!!.displayName()!!.toNative())
214+
// 使有效部分在latest
215+
return Components.empty().append(DefaultComponent(itemMeta!!.displayNameComponent.toList()))
212216
} catch (_: Throwable) {
213-
try {
214-
Components.empty().append(DefaultComponent(itemMeta!!.displayNameComponent.toList()))
215-
} catch (_: Throwable) {
216-
Components.text(itemMeta!!.displayName)
217-
}
218217
}
219-
} else if (Folia.isFolia) {
220-
toTranslatableComponentAdventure()
218+
return Components.text(itemMeta!!.displayName)
221219
} else {
222-
try {
223-
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
224-
Components.translation(getLanguageKey().path)
225-
} else {
226-
Components.text(getI18nName(player))
227-
}
228-
} catch (_: UnsupportedVersionException) {
229-
try {
230-
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
231-
Components.translation(NMS.instance.getLocaleKey(this).path)
220+
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
221+
val key = try {
222+
if (Folia.isFolia) {
223+
(this as Translatable).translationKey()
224+
} else {
225+
getLanguageKey().path
226+
}
232227
} catch (_: Throwable) {
233228
try {
234-
Components.text(getKey())
229+
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
230+
NMS.instance.getLocaleKey(this).path
235231
} catch (_: Throwable) {
236-
Components.text(type.name)
232+
null
237233
}
238234
}
235+
if (key != null) {
236+
return Components.translation(key)
237+
}
238+
}
239+
try {
240+
return Components.text(getI18nName(player))
241+
} catch (_: Throwable) {
239242
}
243+
return Components.text(type.name)
240244
}
241245
}
242246

project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/TrChatVelocity.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import taboolib.common.platform.Plugin
77
import taboolib.common.platform.ProxyCommandSender
88
import taboolib.common.platform.command.command
99
import taboolib.common.platform.command.suggest
10+
import taboolib.common.platform.function.console
1011
import taboolib.common.platform.function.pluginVersion
1112
import taboolib.common.util.unsafeLazy
1213
import taboolib.module.lang.sendLang
@@ -26,8 +27,8 @@ object TrChatVelocity : Plugin() {
2627

2728
override fun onLoad() {
2829
plugin.server.channelRegistrar.register(VelocityProxyManager.incoming, VelocityProxyManager.outgoing)
29-
VelocityConsole().sendLang("Plugin-Loading", plugin.server.version.version)
30-
VelocityConsole().sendLang("Plugin-Proxy-Supported", "Velocity")
30+
console().sendLang("Plugin-Loading", plugin.server.version.version)
31+
console().sendLang("Plugin-Proxy-Supported", "Velocity")
3132
}
3233

3334
override fun onEnable() {
@@ -42,7 +43,7 @@ object TrChatVelocity : Plugin() {
4243
}
4344
}
4445
}
45-
VelocityConsole().sendLang("Plugin-Enabled", pluginVersion)
46+
console().sendLang("Plugin-Enabled", pluginVersion)
4647
}
4748

4849
}

project/runtime-velocity/src/main/kotlin/me/arasple/mc/trchat/module/internal/VelocityConsole.kt

-41
This file was deleted.

0 commit comments

Comments
 (0)