-
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/armor stand module #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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.
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| 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 { | ||||||||||||
|
|
@@ -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)) | ||||||||||||
|
Comment on lines
+45
to
+46
|
||||||||||||
| 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) |
There was a problem hiding this comment.
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.