Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .idea/copilot.data.migration.agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.edit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules/VanillaPlus.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules/VanillaPlus.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions src/main/kotlin/org/xodium/vanillaplus/handlers/RenameHandler.kt

This file was deleted.

52 changes: 33 additions & 19 deletions src/main/kotlin/org/xodium/vanillaplus/handlers/SwapHandler.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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))
Comment on lines +40 to +41
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swap logic is incorrect. Line 41 sets OFF_HAND to the value that was just set on HAND (line 40), resulting in both slots having the same item instead of swapping them. A temporary variable is needed to store one item before the swap. The same issue exists in the SWAP_WITH_HEAD case at lines 45-46.

Copilot uses AI. Check for mistakes.
}

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))
Comment on lines +45 to +46
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swap logic is incorrect. Line 46 sets HEAD to the value that was just set on HAND (line 45), resulting in both slots having the same item instead of swapping them. A temporary variable is needed to store one item before the swap.

Suggested change
entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD))
entity.setItem(EquipmentSlot.HEAD, entity.getItem(EquipmentSlot.HAND))
val handItem = entity.getItem(EquipmentSlot.HAND)
entity.setItem(EquipmentSlot.HAND, entity.getItem(EquipmentSlot.HEAD))
entity.setItem(EquipmentSlot.HEAD, handItem)

Copilot uses AI. Check for mistakes.
}
}
}
}

else -> throw IllegalArgumentException("Invalid Pose action")
}
} catch (e: Exception) {
instance.logger.warning("Failed to process swap packet: ${e.message}")
e.printStackTrace()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +21,6 @@ internal class ArmorStandModule : ModuleInterface<ArmorStandModule.Config> {
instance.server.messenger.apply {
registerIncomingPluginChannel(instance, "armorposer:sync_packet", SyncHandler())
registerIncomingPluginChannel(instance, "armorposer:swap_packet", SwapHandler())
registerIncomingPluginChannel(instance, "armorposer:rename_packet", RenameHandler())
}
}
}
Expand Down
Loading