diff --git a/build.gradle.kts b/build.gradle.kts index 2093439..8c32d8f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,7 @@ allprojects { apply(plugin = "kotlin") apply(plugin = "org.jetbrains.dokka") group = "kr.toxicity.healthbar" - version = "3.2" + version = "3.3" repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") @@ -191,6 +191,8 @@ tasks { dependencies { exclude(dependency("org.jetbrains:annotations:13.0")) } + } + build { finalizedBy(sourceJar) finalizedBy(dokkaJar) } diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt index 85c69e1..c296e9e 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt @@ -12,7 +12,6 @@ import kr.toxicity.healthbar.util.PLUGIN import kr.toxicity.healthbar.util.asyncTaskTimer import org.bukkit.entity.Player import java.util.* -import java.util.concurrent.ConcurrentHashMap class HealthBarPlayerImpl( private val player: Player @@ -20,10 +19,12 @@ class HealthBarPlayerImpl( override fun player(): Player = player override fun compareTo(other: HealthBarPlayer): Int = player.uniqueId.compareTo(other.player().uniqueId) - private val updaterMap = ConcurrentHashMap() + private val updaterMap = HashMap() private val task = asyncTaskTimer(1, 1) { - updaterMap.values.removeIf { - !it.update() + synchronized(updaterMap) { + updaterMap.values.removeIf { + !it.update() + } } } @@ -37,13 +38,17 @@ class HealthBarPlayerImpl( } override fun clear() { - updaterMap.values.removeIf { - it.remove() - true + synchronized(updaterMap) { + updaterMap.values.removeIf { + it.remove() + true + } } } - override fun updaterMap(): MutableMap = updaterMap + override fun updaterMap(): MutableMap = synchronized(updaterMap) { + updaterMap + } override fun showHealthBar(healthBar: HealthBar, trigger: HealthBarTrigger, entity: HealthBarEntity) { if (ConfigManagerImpl.blacklistEntityType().contains(entity.entity().type)) return @@ -59,9 +64,11 @@ class HealthBarPlayerImpl( entity ) if (!healthBar.condition().apply(data)) return - updaterMap.computeIfAbsent(entity.entity().uniqueId) { - HealthBarUpdaterGroupImpl(this, entity) - }.addHealthBar(data) + synchronized(updaterMap) { + updaterMap.computeIfAbsent(entity.entity().uniqueId) { + HealthBarUpdaterGroupImpl(this, entity) + }.addHealthBar(data) + } } override fun equals(other: Any?): Boolean { diff --git a/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt b/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt index 1288f4a..2c0bec8 100644 --- a/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt +++ b/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.v1_19_R3.CraftWorld import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer import org.bukkit.craftbukkit.v1_19_R3.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_19_R3.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as Int2ReferenceOpenHashMap<*>)[i] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -226,7 +240,7 @@ class NMSImpl: NMS { backgroundColor = 0 lineWidth = Int.MAX_VALUE brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -250,7 +264,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) } diff --git a/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt b/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt index a792761..e9668f5 100644 --- a/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt +++ b/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.v1_20_R1.CraftWorld import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer import org.bukkit.craftbukkit.v1_20_R1.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_20_R1.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as Int2ReferenceOpenHashMap<*>)[i] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -232,7 +246,7 @@ class NMSImpl: NMS { set(TextDisplay.DATA_LINE_WIDTH_ID, Int.MAX_VALUE) } brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -256,7 +270,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) } diff --git a/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt b/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt index 7267544..6af91ce 100644 --- a/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt +++ b/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftWorld import org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer import org.bukkit.craftbukkit.v1_20_R2.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_20_R2.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as Int2ReferenceOpenHashMap<*>)[i] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -228,7 +242,7 @@ class NMSImpl: NMS { set(TextDisplay.DATA_LINE_WIDTH_ID, Int.MAX_VALUE) } brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -252,7 +266,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) } diff --git a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt index 4e167b8..d6a7e16 100644 --- a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt +++ b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.v1_20_R3.CraftWorld import org.bukkit.craftbukkit.v1_20_R3.entity.CraftLivingEntity import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer import org.bukkit.craftbukkit.v1_20_R3.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_20_R3.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as Int2ReferenceOpenHashMap<*>)[i] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -228,7 +242,7 @@ class NMSImpl: NMS { set(TextDisplay.DATA_LINE_WIDTH_ID, Int.MAX_VALUE) } brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -252,7 +266,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) } diff --git a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt index 72c2096..7edb98f 100644 --- a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt +++ b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.CraftWorld import org.bukkit.craftbukkit.entity.CraftLivingEntity import org.bukkit.craftbukkit.entity.CraftPlayer import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as Int2ReferenceOpenHashMap<*>)[i] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -228,7 +242,7 @@ class NMSImpl: NMS { set(TextDisplay.DATA_LINE_WIDTH_ID, Int.MAX_VALUE) } brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -252,7 +266,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) } diff --git a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt index ff22ebe..03f7a56 100644 --- a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt +++ b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt @@ -16,6 +16,7 @@ import kr.toxicity.healthbar.api.trigger.PacketTrigger import net.kyori.adventure.bossbar.BossBar import net.kyori.adventure.pointer.Pointers import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.network.Connection import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerLevel @@ -27,6 +28,7 @@ import net.minecraft.world.entity.Display.TextDisplay import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.level.entity.LevelEntityGetter +import net.minecraft.world.level.entity.LevelEntityGetterAdapter import net.minecraft.world.level.entity.PersistentEntitySectionManager import org.bukkit.Bukkit import org.bukkit.GameMode @@ -37,6 +39,7 @@ import org.bukkit.craftbukkit.CraftWorld import org.bukkit.craftbukkit.entity.CraftLivingEntity import org.bukkit.craftbukkit.entity.CraftPlayer import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.util.CraftChatMessage import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.event.entity.EntityDamageEvent @@ -74,6 +77,8 @@ class NMSImpl: NMS { } private val entityTracker = ServerLevel::class.java.fields.firstOrNull { it.type == PersistentEntitySectionManager::class.java + }?.apply { + isAccessible = true } private val getEntityById: (LevelEntityGetter, Int) -> net.minecraft.world.entity.Entity? = if (plugin.isPaper) EntityLookup::class.java.declaredFields.first { @@ -83,7 +88,7 @@ class NMSImpl: NMS { { e, i -> (it[e] as ConcurrentLong2ReferenceChainedHashTable<*>)[i.toLong()] as? net.minecraft.world.entity.Entity } - } else PersistentEntitySectionManager::class.java.declaredFields.first { + } else LevelEntityGetterAdapter::class.java.declaredFields.first { net.minecraft.world.level.entity.EntityLookup::class.java.isAssignableFrom(it.type) }.let { it.isAccessible = true @@ -99,6 +104,15 @@ class NMSImpl: NMS { it[p] as Int } } + private val textVanilla: (Component) -> net.minecraft.network.chat.Component = if (plugin.isPaper) { + { + PaperAdventure.asVanilla(it) + } + } else { + { + CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(it)) + } + } override fun foliaAdapt(player: Player): Player { val handle = (player as CraftPlayer).handle @@ -228,7 +242,7 @@ class NMSImpl: NMS { set(TextDisplay.DATA_LINE_WIDTH_ID, Int.MAX_VALUE) } brightnessOverride = Brightness(15, 15) - text = PaperAdventure.asVanilla(component) + text = textVanilla(component) moveTo( location.x, location.y, @@ -264,7 +278,7 @@ class NMSImpl: NMS { } override fun text(component: Component) { - display.text = PaperAdventure.asVanilla(component) + display.text = textVanilla(component) connection.send(ClientboundSetEntityDataPacket(display.id, display.entityData.nonDefaultValues!!)) }