diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java index f66fe3a6..a5fe0ed3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java @@ -6,6 +6,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.RemovalCause; @@ -21,6 +22,7 @@ import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.packets.LibsPackets; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -229,6 +231,19 @@ public class PlayerSkinHandler implements Listener { } } + private void addMetadata(Player player, PlayerSkin skin) { + PlayerDisguise disguise = skin.getDisguise().get(); + Entity entity = disguise.getEntity(); + WrappedDataWatcher watcher = DisguiseUtilities + .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher()); + + PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true) + .createPacket(entity.getEntityId(), watcher, true); + + skin.getSleptPackets().computeIfAbsent(4, (a) -> new ArrayList<>()).add(metaPacket); + } + private void addTeleport(Player player, PlayerSkin skin) { PlayerDisguise disguise = skin.getDisguise().get(); @@ -281,6 +296,7 @@ public class PlayerSkinHandler implements Listener { if (skin.isSleepPackets()) { addTeleport(player, skin); + addMetadata(player, skin); } try { 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 d2a5923f..0aed4746 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 @@ -233,11 +233,7 @@ public class PacketHandlerSpawn implements IPacketHandler { packets.addPacket(spawnPlayer); - WrappedDataWatcher dataWatcher = DisguiseUtilities - .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), - disguise.getWatcher()); - - WrappedDataWatcher toSend = dataWatcher; + WrappedDataWatcher toSend; if (!normalPlayerDisguise) { toSend = new WrappedDataWatcher(); @@ -246,6 +242,10 @@ public class PacketHandlerSpawn implements IPacketHandler { // Set invis toSend.setObject(obj, (byte) 32); + } else { + toSend = DisguiseUtilities + .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), + disguise.getWatcher()); } if (NmsVersion.v1_15.isSupported()) { @@ -257,14 +257,6 @@ public class PacketHandlerSpawn implements IPacketHandler { } else { spawnPlayer.getDataWatcherModifier().write(0, toSend); } - - if (!normalPlayerDisguise) { - PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() - .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, dataWatcher, true) - .createPacket(entityId, dataWatcher, true); - - skin.getSleptPackets().computeIfAbsent(4, (a) -> new ArrayList<>()).add(metaPacket); - } } else if (disguise.isMobDisguise() || disguise.getType() == DisguiseType.ARMOR_STAND) { Vector vec = disguisedEntity.getVelocity();