Resend self disguise armor, clean spawn armor, don't cancel armor but wipe it to air

This commit is contained in:
libraryaddict 2019-11-18 16:57:00 +13:00
parent c787a1daae
commit a09a86062f
3 changed files with 25 additions and 16 deletions

View File

@ -1594,7 +1594,7 @@ public class DisguiseUtilities {
.createPacket(0, player.getPassenger(), player)); .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.createEnumItemSlot(EquipmentSlot.HEAD),
ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
@ -1623,7 +1623,7 @@ public class DisguiseUtilities {
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND), .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND),
ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand())));*/ ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand())));
Location loc = player.getLocation(); Location loc = player.getLocation();

View File

@ -40,7 +40,12 @@ public class PacketHandlerEquipment implements IPacketHandler {
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) { Entity entity) {
if (packetsHandler.isCancelMeta(disguise, observer)) { 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; return;
} }

View File

@ -378,29 +378,33 @@ public class PacketHandlerSpawn implements IPacketHandler {
packets.addPacket(newPacket); 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; (disguise.isPlayerDisguise() && disguisedEntity != observer) && disguisedEntity instanceof LivingEntity;
// This sends the armor packets so that the player isn't naked. // 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()) { for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemstack = disguise.getWatcher().getItemStack(slot); // Get what the disguise wants to show for its armor
ItemStack entityItem; ItemStack itemToSend = disguise.getWatcher().getItemStack(slot);
if (itemstack == null || itemstack.getType() == Material.AIR) { // If the disguise armor isn't visible
if (requiresArmor) { if (itemToSend == null || itemToSend.getType() == Material.AIR) {
itemstack = ReflectionManager.getEquipment(slot, disguisedEntity); // 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; continue;
} }
} else { } else {
// We don't need to send natural armor and disguise armor isn't visible
continue; continue;
} }
} } else if (!delayedArmor && disguisedEntity instanceof LivingEntity) {
if (!requiresArmor && disguisedEntity instanceof LivingEntity) {
ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity); ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity);
// If the item was going to be sent anyways
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
continue; continue;
} }
@ -412,9 +416,9 @@ public class PacketHandlerSpawn implements IPacketHandler {
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());
mods.write(1, ReflectionManager.createEnumItemSlot(slot)); 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); packets.addDelayedPacket(packet, 7);
} else { } else {
packets.addDelayedPacket(packet); packets.addDelayedPacket(packet);