From 857669fa864d52c001b0c7f861044167eec480a5 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 30 Nov 2013 23:09:29 +1300 Subject: [PATCH] Fixed armor helmet not appearing if you have no helmet and are holding a item --- .../disguise/disguisetypes/FlagWatcher.java | 1 + .../disguise/utilities/PacketsManager.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index a4a4c5f6..4a3de874 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -25,6 +25,7 @@ import me.libraryaddict.disguise.utilities.ReflectionManager; public class FlagWatcher { public enum SlotType { BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1); + // The ints is for bukkit. Not nms slots. private int slotNo = 0; private SlotType(int no) { diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 35c1c76d..ae8e4ebb 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -130,23 +130,26 @@ public class PacketsManager { disguise.setEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); ArrayList packets = new ArrayList(); - for (int i = 0; i < 5; i++) { - int slot = i - 1; - if (slot < 0) - slot = 4; - org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); + // This sends the armor packets so that the player isn't naked. + for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++) { + int armorSlot = nmsSlot - 1; + if (armorSlot < 0) + armorSlot = 4; + org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(armorSlot); if (itemstack != null && itemstack.getTypeId() != 0) { ItemStack item = null; - if (disguisedEntity instanceof LivingEntity) - if (i != 4) - item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[i]; - else + if (disguisedEntity instanceof LivingEntity) { + if (nmsSlot == 0) { item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand(); + } else { + item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[armorSlot]; + } + } if (item == null || item.getType() == Material.AIR) { PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT); StructureModifier mods = packet.getModifier(); mods.write(0, disguisedEntity.getEntityId()); - mods.write(1, i); + mods.write(1, nmsSlot); mods.write(2, ReflectionManager.getNmsItem(itemstack)); packets.add(packet); }