From a09a86062f54249b72b3c5c12b8ac4445c0b8c76 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 18 Nov 2019 16:57:00 +1300 Subject: [PATCH] Resend self disguise armor, clean spawn armor, don't cancel armor but wipe it to air --- .../disguise/utilities/DisguiseUtilities.java | 4 +-- .../PacketHandlerEquipment.java | 7 ++++- .../packethandlers/PacketHandlerSpawn.java | 30 +++++++++++-------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index f097d9a6..0016b813 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -1594,7 +1594,7 @@ public class DisguiseUtilities { .createPacket(0, player.getPassenger(), player)); } - /*sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, + sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), @@ -1623,7 +1623,7 @@ public class DisguiseUtilities { ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND), - ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand())));*/ + ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand()))); Location loc = player.getLocation(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerEquipment.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerEquipment.java index 3a0f0f0d..3c86718e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerEquipment.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerEquipment.java @@ -40,7 +40,12 @@ public class PacketHandlerEquipment implements IPacketHandler { public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) { if (packetsHandler.isCancelMeta(disguise, observer)) { - packets.clear(); + PacketContainer equipPacket = sentPacket.shallowClone(); + + packets.addPacket(equipPacket); + + equipPacket.getModifier() + .write(2, ReflectionManager.getNmsItem(new ItemStack(Material.AIR))); return; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index feb33299..62c1d1ca 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -378,29 +378,33 @@ public class PacketHandlerSpawn implements IPacketHandler { packets.addPacket(newPacket); } - boolean requiresArmor = + // If armor must be sent because its currently not displayed and would've been sent normally + boolean delayedArmor = (disguise.isPlayerDisguise() && disguisedEntity != observer) && disguisedEntity instanceof LivingEntity; // This sends the armor packets so that the player isn't naked. - if (DisguiseConfig.isEquipmentPacketsEnabled() || requiresArmor) { + if (DisguiseConfig.isEquipmentPacketsEnabled() || delayedArmor) { for (EquipmentSlot slot : EquipmentSlot.values()) { - ItemStack itemstack = disguise.getWatcher().getItemStack(slot); - ItemStack entityItem; + // Get what the disguise wants to show for its armor + ItemStack itemToSend = disguise.getWatcher().getItemStack(slot); - if (itemstack == null || itemstack.getType() == Material.AIR) { - if (requiresArmor) { - itemstack = ReflectionManager.getEquipment(slot, disguisedEntity); + // If the disguise armor isn't visible + if (itemToSend == null || itemToSend.getType() == Material.AIR) { + // If we need to send the natural armor if possible + if (delayedArmor) { + itemToSend = ReflectionManager.getEquipment(slot, disguisedEntity); - if (itemstack == null || itemstack.getType() == Material.AIR) { + // If natural armor isn't sent either + if (itemToSend == null || itemToSend.getType() == Material.AIR) { continue; } } else { + // We don't need to send natural armor and disguise armor isn't visible continue; } - } - - if (!requiresArmor && disguisedEntity instanceof LivingEntity) { + } else if (!delayedArmor && disguisedEntity instanceof LivingEntity) { ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity); + // If the item was going to be sent anyways if (item != null && item.getType() != Material.AIR) { continue; } @@ -412,9 +416,9 @@ public class PacketHandlerSpawn implements IPacketHandler { mods.write(0, disguisedEntity.getEntityId()); mods.write(1, ReflectionManager.createEnumItemSlot(slot)); - mods.write(2, ReflectionManager.getNmsItem(itemstack)); + mods.write(2, ReflectionManager.getNmsItem(itemToSend)); - if (requiresArmor) { + if (delayedArmor) { packets.addDelayedPacket(packet, 7); } else { packets.addDelayedPacket(packet);