Skip to content

Commit

Permalink
[2.2.0-beta5] Fix ?
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlicker committed Oct 5, 2024
1 parent ded73b5 commit a698c6e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 99 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ subprojects {
install(Bukkit, BungeeCord, Velocity)
}
version {
taboolib = "6.2.0-beta11"
taboolib = "6.2.0-beta16"
coroutines = null
// isSkipKotlin = true
// isSkipKotlinRelocate = true
Expand All @@ -61,7 +61,7 @@ subprojects {
compileOnly(kotlin("stdlib"))
compileOnly("com.google.code.gson:gson:2.8.5")
compileOnly("com.google.guava:guava:21.0")
compileOnly("net.kyori:adventure-api:4.16.0")
compileOnly("net.kyori:adventure-api:4.17.0")
}

// 编译配置
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion project/module-adventure/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
compileOnly(project(":project:common"))
compileOnly(project(":project:module-nms"))
compileOnly("net.kyori:adventure-platform-bukkit:4.3.2")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.4")
compileOnly(fileTree(rootDir.resolve("libs")))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package me.arasple.mc.trchat.module.adventure

import me.arasple.mc.trchat.api.nms.NMS
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.inventory.ItemStack
import taboolib.library.reflex.Reflex.Companion.invokeMethod
import taboolib.module.chat.ComponentText
import taboolib.module.chat.Components
import taboolib.module.nms.Packet

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

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

fun ItemStack.toTranslatableComponentAdventure(): ComponentText {
return Component.translatable(this).toNative()
}

fun ComponentText.hoverItemAdventure(item: ItemStack): ComponentText {
return toAdventure().hoverEvent(item).toNative()
}

fun Packet.getComponent(): ComponentText? {
return when (name) {
"ClientboundSystemChatPacket" -> {
val iChat = source.invokeMethod<Any>("a", findToParent = false, remap = false) ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
"PacketPlayOutChat" -> {
val iChat = read<Any>("a") ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
else -> error("Unsupported packet $name")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ abstract class NMS {
@JvmStatic
val instance by unsafeLazy {
if (MinecraftVersion.majorLegacy < 12005) nmsProxy<NMS>()
else nmsProxy<NMS>("me.arasple.mc.trchat.api.nms.NMSImpl12100")
else nmsProxy<NMS>("me.arasple.mc.trchat.api.nms.NMSImpl12005")
}

// 1.20.4-
val whitelistTags = arrayOf(
// 附魔
"ench",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package me.arasple.mc.trchat.api.nms

import me.arasple.mc.trchat.util.ServerUtil
import net.minecraft.network.chat.IChatBaseComponent
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_20_R3.util.CraftChatMessage
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.common.platform.function.adaptPlayer
import taboolib.module.chat.ComponentText
import taboolib.module.nms.MinecraftLanguage
import taboolib.module.nms.getLanguageKey
import taboolib.platform.Folia
import taboolib.platform.util.hoverItem
import java.util.*

class NMSImpl12100 : NMS() {
class NMSImpl12005 : NMS() {

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

override fun sendMessage(receiver: Player, component: ComponentText, sender: UUID?, usePacket: Boolean) {
component.sendTo(adaptPlayer(receiver))
if (!usePacket || Folia.isFolia || ServerUtil.isModdedServer) {
component.sendTo(adaptPlayer(receiver))
return
}
val player = (receiver as CraftPlayer).handle
player.sendSystemMessage(craftChatMessageFromComponent(component) as IChatBaseComponent)
}

override fun hoverItem(component: ComponentText, itemStack: ItemStack): ComponentText {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.arasple.mc.trchat.module.display

import me.arasple.mc.trchat.module.adventure.getComponent
import me.arasple.mc.trchat.api.nms.NMS
import me.arasple.mc.trchat.module.conf.file.Settings
import me.arasple.mc.trchat.module.display.channel.Channel
import me.arasple.mc.trchat.module.display.channel.PrivateChannel
Expand All @@ -9,6 +9,9 @@ import me.arasple.mc.trchat.util.color.MessageColors
import me.arasple.mc.trchat.util.data
import org.bukkit.entity.Player
import taboolib.expansion.getDataContainer
import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.module.chat.ComponentText
import taboolib.module.chat.Components
import taboolib.module.nms.Packet
import taboolib.module.nms.sendPacket
import java.util.*
Expand Down Expand Up @@ -109,6 +112,20 @@ class ChatSession(val player: Player) {
sessions -= player.uniqueId
}

private fun Packet.getComponent(): ComponentText? {
return when (name) {
"ClientboundSystemChatPacket" -> {
val iChat = source.getProperty<Any>("content", findToParent = false) ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
"PacketPlayOutChat" -> {
val iChat = read<Any>("a") ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
else -> error("Unsupported packet $name")
}
}

data class ChatMessage(val packet: Any, val message: String?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Text(val content: String, val condition: Condition?) {
text = HookPlugin.getItemsAdder().replaceFontImages(text, null)
}
return if (isDragonCoreHooked) {
DefaultComponent(listOf(TextComponent(text.replaceWithOrder(*vars).colorify())))
// 使有效部分在latest
Components.empty().append(DefaultComponent(listOf(TextComponent(text.replaceWithOrder(*vars).colorify()))))
} else {
Components.text(text.replaceWithOrder(*vars).colorify())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ import com.google.common.cache.CacheBuilder
import me.arasple.mc.trchat.api.event.TrChatItemShowEvent
import me.arasple.mc.trchat.api.impl.BukkitProxyManager
import me.arasple.mc.trchat.api.nms.NMS
import me.arasple.mc.trchat.module.adventure.toNative
import me.arasple.mc.trchat.module.adventure.toTranslatableComponentAdventure
import me.arasple.mc.trchat.module.conf.file.Functions
import me.arasple.mc.trchat.module.display.function.Function
import me.arasple.mc.trchat.module.display.function.StandardFunction
import me.arasple.mc.trchat.module.internal.hook.HookPlugin
import me.arasple.mc.trchat.module.internal.hook.type.HookDisplayItem
import me.arasple.mc.trchat.module.internal.script.Reaction
import me.arasple.mc.trchat.util.*
import net.kyori.adventure.translation.Translatable
import org.bukkit.Material
import org.bukkit.block.ShulkerBox
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.BlockStateMeta
import taboolib.common.UnsupportedVersionException
import taboolib.common.io.digest
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
import taboolib.common.platform.function.info
import taboolib.common.util.asList
import taboolib.common.util.replaceWithOrder
import taboolib.common.util.resettableLazy
Expand All @@ -37,7 +36,6 @@ import taboolib.module.configuration.ConfigNode
import taboolib.module.configuration.ConfigNodeTransfer
import taboolib.module.nms.MinecraftVersion
import taboolib.module.nms.getI18nName
import taboolib.module.nms.getKey
import taboolib.module.nms.getLanguageKey
import taboolib.module.ui.buildMenu
import taboolib.module.ui.type.Chest
Expand Down Expand Up @@ -140,6 +138,7 @@ object ItemShow : Function("ITEM") {
Components.text(part.text.translate(proxySender).replaceWithOrder(newItem.amount, sha1))
}
component.applyStyle(type, part, i, proxySender, newItem.amount, sha1).hoverItemFixed(newItem)
.also { info("$i: ${it.toRawMessage()}") }
}
} else {
sender.getComponentFromLang("Function-Item-Show-Format-New", newItem.amount) { type, i, part, proxySender ->
Expand Down Expand Up @@ -206,37 +205,42 @@ object ItemShow : Function("ITEM") {

@Suppress("Deprecation")
private fun ItemStack.getNameComponent(player: Player): ComponentText {
return if (!originName && itemMeta?.hasDisplayName() == true) {
if (!originName && itemMeta?.hasDisplayName() == true) {
// try {
// return itemMeta!!.displayName()!!.toNative()
// } catch (_: Throwable) {
// }
try {
Components.empty().append(itemMeta!!.displayName()!!.toNative())
// 使有效部分在latest
return Components.empty().append(DefaultComponent(itemMeta!!.displayNameComponent.toList()))
} catch (_: Throwable) {
try {
Components.empty().append(DefaultComponent(itemMeta!!.displayNameComponent.toList()))
} catch (_: Throwable) {
Components.text(itemMeta!!.displayName)
}
}
} else if (Folia.isFolia) {
toTranslatableComponentAdventure()
return Components.text(itemMeta!!.displayName)
} else {
try {
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
Components.translation(getLanguageKey().path)
} else {
Components.text(getI18nName(player))
}
} catch (_: UnsupportedVersionException) {
try {
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
Components.translation(NMS.instance.getLocaleKey(this).path)
if (MinecraftVersion.isHigherOrEqual(MinecraftVersion.V1_15)) {
val key = try {
if (Folia.isFolia) {
(this as Translatable).translationKey()
} else {
getLanguageKey().path
}
} catch (_: Throwable) {
try {
Components.text(getKey())
// 玄学问题 https://github.com/TrPlugins/TrChat/issues/344
NMS.instance.getLocaleKey(this).path
} catch (_: Throwable) {
Components.text(type.name)
null
}
}
if (key != null) {
return Components.translation(key)
}
}
try {
return Components.text(getI18nName(player))
} catch (_: Throwable) {
}
return Components.text(type.name)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import taboolib.common.platform.Plugin
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.command.command
import taboolib.common.platform.command.suggest
import taboolib.common.platform.function.console
import taboolib.common.platform.function.pluginVersion
import taboolib.common.util.unsafeLazy
import taboolib.module.lang.sendLang
Expand All @@ -26,8 +27,8 @@ object TrChatVelocity : Plugin() {

override fun onLoad() {
plugin.server.channelRegistrar.register(VelocityProxyManager.incoming, VelocityProxyManager.outgoing)
VelocityConsole().sendLang("Plugin-Loading", plugin.server.version.version)
VelocityConsole().sendLang("Plugin-Proxy-Supported", "Velocity")
console().sendLang("Plugin-Loading", plugin.server.version.version)
console().sendLang("Plugin-Proxy-Supported", "Velocity")
}

override fun onEnable() {
Expand All @@ -42,7 +43,7 @@ object TrChatVelocity : Plugin() {
}
}
}
VelocityConsole().sendLang("Plugin-Enabled", pluginVersion)
console().sendLang("Plugin-Enabled", pluginVersion)
}

}

This file was deleted.

0 comments on commit a698c6e

Please sign in to comment.