Fixed armor helmet not appearing if you have no helmet and are holding a item

This commit is contained in:
libraryaddict 2013-11-30 23:09:29 +13:00
parent c63a08eca4
commit 857669fa86
2 changed files with 14 additions and 10 deletions

View File

@ -25,6 +25,7 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
public class FlagWatcher { public class FlagWatcher {
public enum SlotType { public enum SlotType {
BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1); BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1);
// The ints is for bukkit. Not nms slots.
private int slotNo = 0; private int slotNo = 0;
private SlotType(int no) { private SlotType(int no) {

View File

@ -130,23 +130,26 @@ public class PacketsManager {
disguise.setEntity(disguisedEntity); disguise.setEntity(disguisedEntity);
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>(); ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>();
for (int i = 0; i < 5; i++) { // This sends the armor packets so that the player isn't naked.
int slot = i - 1; for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++) {
if (slot < 0) int armorSlot = nmsSlot - 1;
slot = 4; if (armorSlot < 0)
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); armorSlot = 4;
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(armorSlot);
if (itemstack != null && itemstack.getTypeId() != 0) { if (itemstack != null && itemstack.getTypeId() != 0) {
ItemStack item = null; ItemStack item = null;
if (disguisedEntity instanceof LivingEntity) if (disguisedEntity instanceof LivingEntity) {
if (i != 4) if (nmsSlot == 0) {
item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[i];
else
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand(); item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand();
} else {
item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[armorSlot];
}
}
if (item == null || item.getType() == Material.AIR) { if (item == null || item.getType() == Material.AIR) {
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT); PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());
mods.write(1, i); mods.write(1, nmsSlot);
mods.write(2, ReflectionManager.getNmsItem(itemstack)); mods.write(2, ReflectionManager.getNmsItem(itemstack));
packets.add(packet); packets.add(packet);
} }