From 5ee698f761ee811158cd3d8d85419f861151b5f0 Mon Sep 17 00:00:00 2001 From: Illyrius Date: Wed, 12 Nov 2025 13:45:30 +0100 Subject: [PATCH 1/3] removed RenameHandler.kt as you can rename easily with nametag Signed-off-by: Illyrius --- .idea/copilot.data.migration.agent.xml | 4 +-- .idea/copilot.data.migration.ask.xml | 6 ++++ .idea/copilot.data.migration.ask2agent.xml | 6 ++++ .idea/copilot.data.migration.edit.xml | 6 ++++ ..._paper_paper_api_1_21_10_R0_1_SNAPSHOT.xml | 5 --- .idea/modules/VanillaPlus.main.iml | 1 - .idea/modules/VanillaPlus.test.iml | 1 - .../vanillaplus/handlers/RenameHandler.kt | 31 ------------------- .../vanillaplus/modules/ArmorStandModule.kt | 2 -- 9 files changed, 19 insertions(+), 43 deletions(-) create mode 100644 .idea/copilot.data.migration.ask.xml create mode 100644 .idea/copilot.data.migration.ask2agent.xml create mode 100644 .idea/copilot.data.migration.edit.xml delete mode 100644 src/main/kotlin/org/xodium/vanillaplus/handlers/RenameHandler.kt diff --git a/.idea/copilot.data.migration.agent.xml b/.idea/copilot.data.migration.agent.xml index 14f22c4e7..4ea72a911 100644 --- a/.idea/copilot.data.migration.agent.xml +++ b/.idea/copilot.data.migration.agent.xml @@ -1,8 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/copilot.data.migration.ask.xml b/.idea/copilot.data.migration.ask.xml new file mode 100644 index 000000000..7ef04e2ea --- /dev/null +++ b/.idea/copilot.data.migration.ask.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 000000000..1f2ea11e7 --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.edit.xml b/.idea/copilot.data.migration.edit.xml new file mode 100644 index 000000000..8648f9401 --- /dev/null +++ b/.idea/copilot.data.migration.edit.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__io_papermc_paper_paper_api_1_21_10_R0_1_SNAPSHOT.xml b/.idea/libraries/Gradle__io_papermc_paper_paper_api_1_21_10_R0_1_SNAPSHOT.xml index d05650880..9cef7876f 100644 --- a/.idea/libraries/Gradle__io_papermc_paper_paper_api_1_21_10_R0_1_SNAPSHOT.xml +++ b/.idea/libraries/Gradle__io_papermc_paper_paper_api_1_21_10_R0_1_SNAPSHOT.xml @@ -6,11 +6,6 @@ - - - - - diff --git a/.idea/modules/VanillaPlus.main.iml b/.idea/modules/VanillaPlus.main.iml index dde4fd273..7a22db58e 100644 --- a/.idea/modules/VanillaPlus.main.iml +++ b/.idea/modules/VanillaPlus.main.iml @@ -4,7 +4,6 @@ - PAPER MCP ADVENTURE diff --git a/.idea/modules/VanillaPlus.test.iml b/.idea/modules/VanillaPlus.test.iml index 832085095..28546c8b1 100644 --- a/.idea/modules/VanillaPlus.test.iml +++ b/.idea/modules/VanillaPlus.test.iml @@ -4,7 +4,6 @@ - PAPER MCP ADVENTURE diff --git a/src/main/kotlin/org/xodium/vanillaplus/handlers/RenameHandler.kt b/src/main/kotlin/org/xodium/vanillaplus/handlers/RenameHandler.kt deleted file mode 100644 index 59ae43a22..000000000 --- a/src/main/kotlin/org/xodium/vanillaplus/handlers/RenameHandler.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.xodium.vanillaplus.handlers - -import io.netty.buffer.Unpooled -import net.minecraft.network.FriendlyByteBuf -import org.bukkit.GameMode -import org.bukkit.entity.ArmorStand -import org.bukkit.entity.Player -import org.bukkit.plugin.messaging.PluginMessageListener -import org.xodium.vanillaplus.VanillaPlus.Companion.instance -import org.xodium.vanillaplus.utils.ExtUtils.mm - -/** Handles plugin messages related to renaming an ArmorStand entity. */ -internal class RenameHandler : PluginMessageListener { - override fun onPluginMessageReceived( - channel: String, - player: Player, - message: ByteArray, - ) { - if (channel != "armorposer:rename_packet") return - - val byteBuf = FriendlyByteBuf(Unpooled.wrappedBuffer(message)) - val uuid = byteBuf.readUUID() - val name = byteBuf.readUtf() - val entity = instance.server.getEntity(uuid) - - if (name.isNotEmpty() && entity is ArmorStand && (player.level >= 1 || player.gameMode == GameMode.CREATIVE)) { - player.giveExpLevels(-1) - entity.customName(name.mm()) - } - } -} diff --git a/src/main/kotlin/org/xodium/vanillaplus/modules/ArmorStandModule.kt b/src/main/kotlin/org/xodium/vanillaplus/modules/ArmorStandModule.kt index 5e2a8488d..460ec596d 100644 --- a/src/main/kotlin/org/xodium/vanillaplus/modules/ArmorStandModule.kt +++ b/src/main/kotlin/org/xodium/vanillaplus/modules/ArmorStandModule.kt @@ -8,7 +8,6 @@ import org.bukkit.event.EventHandler import org.bukkit.event.player.PlayerInteractAtEntityEvent import org.bukkit.inventory.EquipmentSlot import org.xodium.vanillaplus.VanillaPlus.Companion.instance -import org.xodium.vanillaplus.handlers.RenameHandler import org.xodium.vanillaplus.handlers.SwapHandler import org.xodium.vanillaplus.handlers.SyncHandler import org.xodium.vanillaplus.interfaces.ModuleInterface @@ -22,7 +21,6 @@ internal class ArmorStandModule : ModuleInterface { instance.server.messenger.apply { registerIncomingPluginChannel(instance, "armorposer:sync_packet", SyncHandler()) registerIncomingPluginChannel(instance, "armorposer:swap_packet", SwapHandler()) - registerIncomingPluginChannel(instance, "armorposer:rename_packet", RenameHandler()) } } } From bd4aaa898c6c1045821b6a4c68d45ba453ff2aef Mon Sep 17 00:00:00 2001 From: Illyrius Date: Wed, 12 Nov 2025 14:00:35 +0100 Subject: [PATCH 2/3] refactor SwapHandler to use DataInputStream for packet processing and improve error handling Signed-off-by: Illyrius --- .../vanillaplus/handlers/SwapHandler.kt | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt b/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt index 1d7c54a0f..3986d5493 100644 --- a/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt +++ b/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt @@ -1,12 +1,15 @@ +@file:Suppress("ktlint:standard:no-wildcard-imports") + package org.xodium.vanillaplus.handlers -import io.netty.buffer.Unpooled -import net.minecraft.network.FriendlyByteBuf import org.bukkit.entity.ArmorStand import org.bukkit.entity.Player import org.bukkit.inventory.EquipmentSlot import org.bukkit.plugin.messaging.PluginMessageListener import org.xodium.vanillaplus.VanillaPlus.Companion.instance +import java.io.ByteArrayInputStream +import java.io.DataInputStream +import java.util.* /** Handles plugin messages related to swapping [ArmorStand] equipment items. */ internal class SwapHandler : PluginMessageListener { @@ -17,27 +20,44 @@ internal class SwapHandler : PluginMessageListener { ) { if (channel != "armorposer:swap_packet") return - val byteBuf = FriendlyByteBuf(Unpooled.wrappedBuffer(message)) - val uuid = byteBuf.readUUID() - val action = byteBuf.readEnum(Action::class.java) - val entity = instance.server.getEntity(uuid) - - if (entity is ArmorStand) { - when (action) { - Action.SWAP_HANDS -> { - entity.setItem(EquipmentSlot.OFF_HAND, entity.getItem(EquipmentSlot.HAND)) - entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.OFF_HAND)) - return - } + try { + ByteArrayInputStream(message).use { byteStream -> + DataInputStream(byteStream).use { inputStream -> + val mostSigBits = inputStream.readLong() + val leastSigBits = inputStream.readLong() + val uuid = UUID(mostSigBits, leastSigBits) + val actionOrdinal = inputStream.readByte().toInt() + val action = + Action.entries.getOrNull(actionOrdinal) ?: run { + instance.logger.warning("Invalid action ordinal: $actionOrdinal") + return + } + val entity = instance.server.getEntity(uuid) - Action.SWAP_WITH_HEAD -> { - entity.setItem(EquipmentSlot.HEAD, entity.getItem(EquipmentSlot.HAND)) - entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD)) - return - } + if (entity is ArmorStand) { + when (action) { + Action.SWAP_HANDS -> { + val handItem = entity.getItem(EquipmentSlot.HAND) + val offHandItem = entity.getItem(EquipmentSlot.OFF_HAND) - else -> throw IllegalArgumentException("Invalid Pose action") + entity.setItem(EquipmentSlot.HAND, offHandItem) + entity.setItem(EquipmentSlot.OFF_HAND, handItem) + } + + Action.SWAP_WITH_HEAD -> { + val handItem = entity.getItem(EquipmentSlot.HAND) + val headItem = entity.getItem(EquipmentSlot.HEAD) + + entity.setItem(EquipmentSlot.HAND, headItem) + entity.setItem(EquipmentSlot.HEAD, handItem) + } + } + } + } } + } catch (e: Exception) { + instance.logger.warning("Failed to process swap packet: ${e.message}") + e.printStackTrace() } } From 5cda8a2edd035c667d5ebb1ddc8c068ad494a5d8 Mon Sep 17 00:00:00 2001 From: Illyrius Date: Wed, 12 Nov 2025 14:58:24 +0100 Subject: [PATCH 3/3] refactor SwapHandler to simplify item swapping logic for ArmorStand Signed-off-by: Illyrius --- .../org/xodium/vanillaplus/handlers/SwapHandler.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt b/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt index 3986d5493..b546f4233 100644 --- a/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt +++ b/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt @@ -37,19 +37,13 @@ internal class SwapHandler : PluginMessageListener { if (entity is ArmorStand) { when (action) { Action.SWAP_HANDS -> { - val handItem = entity.getItem(EquipmentSlot.HAND) - val offHandItem = entity.getItem(EquipmentSlot.OFF_HAND) - - entity.setItem(EquipmentSlot.HAND, offHandItem) - entity.setItem(EquipmentSlot.OFF_HAND, handItem) + entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.OFF_HAND)) + entity.setItem(EquipmentSlot.OFF_HAND, entity.getItem(EquipmentSlot.HAND)) } Action.SWAP_WITH_HEAD -> { - val handItem = entity.getItem(EquipmentSlot.HAND) - val headItem = entity.getItem(EquipmentSlot.HEAD) - - entity.setItem(EquipmentSlot.HAND, headItem) - entity.setItem(EquipmentSlot.HEAD, handItem) + entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD)) + entity.setItem(EquipmentSlot.HEAD, entity.getItem(EquipmentSlot.HAND)) } } }