Skip to content

Commit

Permalink
[6.0.10][publish] fix ComponentText
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed May 15, 2023
1 parent cc0a965 commit 3023800
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package taboolib.module.chat

import net.md_5.bungee.api.chat.BaseComponent
import java.awt.Color

/**
Expand Down Expand Up @@ -135,6 +136,9 @@ interface ComponentText : Source {
/** 移除颜色 */
fun uncolor(): ComponentText

/** 转换为 Spigot 对象 */
fun toSpigotObject(): BaseComponent

companion object {

fun empty(): ComponentText {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ class DefaultComponent() : ComponentText {
return this
}

override fun toSpigotObject(): BaseComponent {
return component
}

/** 释放缓冲区 */
fun flush() {
left.addAll(latest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import org.tabooproject.reflex.Reflex.Companion.getProperty
import org.tabooproject.reflex.Reflex.Companion.invokeMethod
import taboolib.common.Isolated
import taboolib.common.util.unsafeLazy
import taboolib.module.chat.TellrawJson
import taboolib.module.chat.ComponentText
import taboolib.module.chat.RawMessage

fun TellrawJson.hoverItem(itemStack: ItemStack): TellrawJson {
val nmsItemStack = classCraftItemStack.invokeMethod<Any>("asNMSCopy", itemStack, isStatic = true)!!
fun ItemStack.toNMSKeyAndItemData(): Pair<String, String> {
val nmsItemStack = classCraftItemStack.invokeMethod<Any>("asNMSCopy", this, isStatic = true)!!
val nmsKey = try {
itemStack.type.key.key
type.key.key
} catch (ex: NoSuchMethodError) {
val nmsItem = nmsItemStack.invokeMethod<Any>("getItem")!!
val name = nmsItem.getProperty<String>("name")!!
Expand All @@ -26,7 +27,17 @@ fun TellrawJson.hoverItem(itemStack: ItemStack): TellrawJson {
}
key
}
return hoverItem(nmsKey, nmsItemStack.invokeMethod<Any>("getTag")?.toString() ?: "{}")
return nmsKey to (nmsItemStack.invokeMethod<Any>("getTag")?.toString() ?: "{}")
}

fun ComponentText.hoverItem(itemStack: ItemStack): ComponentText {
val (key, data) = itemStack.toNMSKeyAndItemData()
return hoverItem(key, data)
}

fun RawMessage.hoverItem(itemStack: ItemStack): RawMessage {
val (key, data) = itemStack.toNMSKeyAndItemData()
return hoverItem(key, data)
}

private val classCraftItemStack by unsafeLazy {
Expand Down

0 comments on commit 3023800

Please sign in to comment.