Skip to content

Commit 02e2720

Browse files
committed
Support Item hover on 1.20.5+
1 parent a7e670f commit 02e2720

File tree

2 files changed

+52
-57
lines changed

2 files changed

+52
-57
lines changed

bukkit/src/main/java/io/github/rothes/protocolstringreplacer/replacer/containers/ItemContentContainer.java

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@file:Suppress("DEPRECATION")
2+
3+
package io.github.rothes.protocolstringreplacer.replacer.containers
4+
5+
import de.tr7zw.nbtapi.NBT
6+
import io.github.rothes.protocolstringreplacer.plugin
7+
import net.md_5.bungee.api.chat.ItemTag
8+
import net.md_5.bungee.api.chat.hover.content.Item
9+
10+
open class ItemContentContainer(item: Item, root: Container<*>?) : AbstractContainer<Item>(item, root) {
11+
12+
private val container: ItemStackContainer?
13+
14+
init {
15+
if (content.tag != null) {
16+
val nbt = NBT.createNBTObject()
17+
nbt.setString("id", content.id)
18+
if (NEW_NBT) {
19+
nbt.setInteger("count", content.count)
20+
nbt.getOrCreateCompound("components").mergeCompound(NBT.parseNBT(content.tag.nbt))
21+
} else {
22+
nbt.setInteger("Count", content.count)
23+
nbt.getOrCreateCompound("tag").mergeCompound(NBT.parseNBT(content.tag.nbt))
24+
}
25+
val itemStack = NBT.itemStackFromNBT(nbt)!!
26+
container = ItemStackContainer(itemStack, false, root)
27+
} else {
28+
container = null
29+
}
30+
}
31+
32+
override fun createDefaultChildren() {
33+
if (container != null) {
34+
children.add(container)
35+
container.entriesPeriod()
36+
}
37+
}
38+
39+
override fun getResult(): Item {
40+
if (container != null) {
41+
val itemStack = container.result
42+
val nbt = NBT.itemStackToNBT(itemStack)
43+
content.tag = ItemTag.ofNbt(if (NEW_NBT) nbt.getCompound("components").toString() else nbt.getCompound("tag").toString())
44+
}
45+
return content
46+
}
47+
48+
companion object {
49+
private val NEW_NBT = plugin.serverMajorVersion == 20.toByte() && plugin.serverMinorVersion >= 5 || plugin.serverMajorVersion > 20
50+
}
51+
52+
}

0 commit comments

Comments
 (0)