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/handlers/SwapHandler.kt b/src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt
index 1d7c54a0f..b546f4233 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,38 @@ 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)
+ 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)
- 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
- }
+ if (entity is ArmorStand) {
+ when (action) {
+ Action.SWAP_HANDS -> {
+ entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.OFF_HAND))
+ entity.setItem(EquipmentSlot.OFF_HAND, entity.getItem(EquipmentSlot.HAND))
+ }
- Action.SWAP_WITH_HEAD -> {
- entity.setItem(EquipmentSlot.HEAD, entity.getItem(EquipmentSlot.HAND))
- entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD))
- return
+ Action.SWAP_WITH_HEAD -> {
+ entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD))
+ entity.setItem(EquipmentSlot.HEAD, entity.getItem(EquipmentSlot.HAND))
+ }
+ }
+ }
}
-
- else -> throw IllegalArgumentException("Invalid Pose action")
}
+ } catch (e: Exception) {
+ instance.logger.warning("Failed to process swap packet: ${e.message}")
+ e.printStackTrace()
}
}
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())
}
}
}