diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/nms/EmojyNMSHandlers.kt b/core/src/main/kotlin/com/mineinabyss/emojy/nms/EmojyNMSHandlers.kt index e030fa1..c3d0614 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/nms/EmojyNMSHandlers.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/nms/EmojyNMSHandlers.kt @@ -1,18 +1,20 @@ package com.mineinabyss.emojy.nms import com.mineinabyss.emojy.EmojyPlugin +import org.bukkit.Bukkit object EmojyNMSHandlers { - private val SUPPORTED_VERSION = arrayOf("v1_20_R4", "v1_21_R1") - fun setup(emojy: EmojyPlugin): IEmojyNMSHandler { - SUPPORTED_VERSION.forEach { version -> - runCatching { - return Class.forName("com.mineinabyss.emojy.nms.${version}.EmojyNMSHandler").getConstructor(EmojyPlugin::class.java) - .newInstance(emojy) as IEmojyNMSHandler - }.onFailure { it.printStackTrace() } + val nmsPackage = when (Bukkit.getMinecraftVersion()) { + "1.20.5", "1.20.6" -> "v1_20_R4" + "1.21" -> "v1_21_R1" + else -> throw IllegalStateException("Unsupported server version") } + runCatching { + return Class.forName("com.mineinabyss.emojy.nms.${nmsPackage}.EmojyNMSHandler").getConstructor(EmojyPlugin::class.java) + .newInstance(emojy) as IEmojyNMSHandler + }.onFailure { it.printStackTrace() } throw IllegalStateException("Unsupported server version") } diff --git a/v1_21_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R1/EmojyNMSHandler.kt b/v1_21_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R1/EmojyNMSHandler.kt index 5c7d19f..8c6c364 100644 --- a/v1_21_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R1/EmojyNMSHandler.kt +++ b/v1_21_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R1/EmojyNMSHandler.kt @@ -16,12 +16,9 @@ import io.netty.channel.ChannelPromise import io.papermc.paper.adventure.AdventureComponent import io.papermc.paper.adventure.PaperAdventure import io.papermc.paper.network.ChannelInitializeListenerHolder -import net.minecraft.core.NonNullList import net.minecraft.network.Connection import net.minecraft.network.chat.ChatType import net.minecraft.network.chat.Component -import net.minecraft.network.chat.MessageSignature -import net.minecraft.network.chat.SignedMessageBody import net.minecraft.network.protocol.common.ClientboundDisconnectPacket import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket import net.minecraft.network.protocol.common.ClientboundServerLinksPacket @@ -30,10 +27,8 @@ import net.minecraft.network.syncher.EntityDataSerializer import net.minecraft.network.syncher.SynchedEntityData import net.minecraft.world.item.ItemStack import org.bukkit.NamespacedKey -import org.bukkit.ServerLinks import org.bukkit.craftbukkit.inventory.CraftItemStack import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory import java.util.* class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler { @@ -72,21 +67,21 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler { } ?: it }) is ClientboundContainerSetSlotPacket -> ClientboundContainerSetSlotPacket(packet.containerId, packet.stateId, packet.slot, packet.item.transformItemNameLore()) - is ClientboundContainerSetContentPacket -> ClientboundContainerSetContentPacket( - packet.containerId, packet.stateId, NonNullList.of(packet.items.first(), - *packet.items.map { - val inv = connection.player.bukkitEntity.openInventory.topInventory - val bukkit = CraftItemStack.asBukkitCopy(it) - - // If item is firstItem in AnvilInventory we want to set it to have the plain-text displayname - if (inv is AnvilInventory && inv.firstItem == bukkit) - bukkit.itemMeta?.persistentDataContainer?.get(ORIGINAL_ITEM_RENAME_TEXT, DataType.STRING)?.let { og -> - CraftItemStack.asNMSCopy(bukkit.editItemMeta { - setDisplayName(og) - }) - } ?: it.transformItemNameLore() - else it.transformItemNameLore() - }.toTypedArray()), packet.carriedItem) + //is ClientboundContainerSetContentPacket -> ClientboundContainerSetContentPacket( + // packet.containerId, packet.stateId, NonNullList.of(packet.items.first(), + // *packet.items.map { + // val inv = connection.player.bukkitEntity.openInventory.topInventory + // val bukkit = CraftItemStack.asBukkitCopy(it) + + // // If item is firstItem in AnvilInventory we want to set it to have the plain-text displayname + // if (inv is AnvilInventory && inv.firstItem == bukkit) + // bukkit.itemMeta?.persistentDataContainer?.get(ORIGINAL_ITEM_RENAME_TEXT, DataType.STRING)?.let { og -> + // CraftItemStack.asNMSCopy(bukkit.editItemMeta { + // setDisplayName(og) + // }) + // } ?: it.transformItemNameLore() + // else it.transformItemNameLore() + // }.toTypedArray()), packet.carriedItem) is ClientboundBossEventPacket -> { // Access the private field 'operation' val operationField = ClientboundBossEventPacket::class.java.getDeclaredField("operation").apply { isAccessible = true }