Try fix armorstands option for player disguises
This commit is contained in:
		| @@ -153,6 +153,10 @@ public abstract class Disguise { | ||||
|  | ||||
|         try { | ||||
|             for (Player player : DisguiseUtilities.getPerverts(this)) { | ||||
|                 if (isPlayerDisguise() && LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) this)) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 for (PacketContainer packet : packets) { | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||
|                 } | ||||
|   | ||||
| @@ -100,6 +100,16 @@ public class PlayerSkinHandler implements Listener { | ||||
|         }.runTaskTimer(LibsDisguises.getInstance(), 1, 1); | ||||
|     } | ||||
|  | ||||
|     public boolean isSleeping(Player player, PlayerDisguise disguise) { | ||||
|         List<PlayerSkin> disguises = getCache().getIfPresent(player); | ||||
|  | ||||
|         if (disguises == null) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return disguises.stream().anyMatch(d -> d.getDisguise().get() == disguise); | ||||
|     } | ||||
|  | ||||
|     public PlayerSkin addPlayerSkin(Player player, PlayerDisguise disguise) { | ||||
|         tryProcess(player, false); | ||||
|  | ||||
| @@ -335,6 +345,14 @@ public class PlayerSkinHandler implements Listener { | ||||
|                 addMetadata(player, skin); | ||||
|             } | ||||
|  | ||||
|             if (DisguiseConfig.isArmorstandsName() && disguise.isNameVisible() && disguise.getMultiNameLength() > 0) { | ||||
|                 ArrayList<PacketContainer> packets = DisguiseUtilities.getNamePackets(disguise, new String[0]); | ||||
|  | ||||
|                 for (PacketContainer p : packets) { | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, p); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if (skin.isDoTabList()) { | ||||
|                 PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); | ||||
|  | ||||
|   | ||||
| @@ -52,13 +52,11 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|     @Override | ||||
|     public PacketType[] getHandledPackets() { | ||||
|         return new PacketType[]{PacketType.Play.Server.NAMED_ENTITY_SPAWN, PacketType.Play.Server.SPAWN_ENTITY_LIVING, | ||||
|                 PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB, PacketType.Play.Server.SPAWN_ENTITY, | ||||
|                 PacketType.Play.Server.SPAWN_ENTITY_PAINTING}; | ||||
|                 PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB, PacketType.Play.Server.SPAWN_ENTITY, PacketType.Play.Server.SPAWN_ENTITY_PAINTING}; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, | ||||
|                        Entity entity) { | ||||
|     public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) { | ||||
|  | ||||
|         packets.clear(); | ||||
|  | ||||
| @@ -84,8 +82,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|                 if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { | ||||
|                     builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); | ||||
|                 } else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && | ||||
|                         disguisedEntity instanceof Damageable) { | ||||
|                 } else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) { | ||||
|                     builder.baseValue(((Damageable) disguisedEntity).getMaxHealth()); | ||||
|                 } else { | ||||
|                     builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); | ||||
| @@ -104,8 +101,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Location loc = disguisedEntity.getLocation().clone() | ||||
|                 .add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0); | ||||
|         Location loc = disguisedEntity.getLocation().clone().add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0); | ||||
|  | ||||
|         Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null; | ||||
|         Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null; | ||||
| @@ -169,8 +165,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|             boolean visibleOrNewCompat = playerDisguise.isNameVisible() || DisguiseConfig.isScoreboardNames(); | ||||
|  | ||||
|             WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager | ||||
|                     .getGameProfileWithThisSkin(UUID.randomUUID(), visibleOrNewCompat ? playerDisguise.getName() : "", | ||||
|                             playerDisguise.getGameProfile()); | ||||
|                     .getGameProfileWithThisSkin(UUID.randomUUID(), visibleOrNewCompat ? playerDisguise.getName() : "", playerDisguise.getGameProfile()); | ||||
|  | ||||
|             int entityId = disguisedEntity.getEntityId(); | ||||
|             PlayerSkinHandler.PlayerSkin skin; | ||||
| @@ -182,8 +177,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|                 // Add player to the list, necessary to spawn them | ||||
|                 sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0)); | ||||
|  | ||||
|                 List playerList = Collections | ||||
|                         .singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), spawnProfile)); | ||||
|                 List playerList = Collections.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), spawnProfile)); | ||||
|                 sendTab.getModifier().write(1, playerList); | ||||
|  | ||||
|                 packets.addPacket(sendTab); | ||||
| @@ -194,10 +188,8 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|                 skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise); | ||||
|  | ||||
|                 if (LibsPremium.getPaidInformation() != null && | ||||
|                         !LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { | ||||
|                     skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()) | ||||
|                             .add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT)); | ||||
|                 if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { | ||||
|                     skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()).add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT)); | ||||
|                 } | ||||
|             } else { | ||||
|                 skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise); | ||||
| @@ -214,8 +206,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|             // If self disguise, or further than 50 blocks, or not in front of entity | ||||
|             boolean normalPlayerDisguise = observer == disguisedEntity || dist > (50 * 50) || | ||||
|                     (observer.getLocation().add(observer.getLocation().getDirection().normalize()) | ||||
|                             .distanceSquared(disguisedEntity.getLocation()) - dist) < 0.3; | ||||
|                     (observer.getLocation().add(observer.getLocation().getDirection().normalize()).distanceSquared(disguisedEntity.getLocation()) - dist) < 0.3; | ||||
|             sendArmor = normalPlayerDisguise; | ||||
|  | ||||
|             skin.setSleepPackets(!normalPlayerDisguise); | ||||
| @@ -239,21 +230,18 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|             if (!normalPlayerDisguise) { | ||||
|                 toSend = new WrappedDataWatcher(); | ||||
|                 WrappedDataWatcher.WrappedDataWatcherObject obj = | ||||
|                         ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32); | ||||
|                 WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32); | ||||
|  | ||||
|                 // Set invis | ||||
|                 toSend.setObject(obj, (byte) 32); | ||||
|             } else { | ||||
|                 toSend = DisguiseUtilities | ||||
|                         .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), | ||||
|                                 disguise.getWatcher()); | ||||
|                 toSend = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); | ||||
|             } | ||||
|  | ||||
|             if (NmsVersion.v1_15.isSupported()) { | ||||
|                 PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() | ||||
|                         .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true) | ||||
|                         .createPacket(entityId, toSend, true); | ||||
|                 PacketContainer metaPacket = | ||||
|                         ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true) | ||||
|                                 .createPacket(entityId, toSend, true); | ||||
|  | ||||
|                 packets.addPacket(metaPacket); | ||||
|             } else { | ||||
| @@ -315,14 +303,13 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|             mods.write(10, pitch); | ||||
|             mods.write(11, yaw); | ||||
|  | ||||
|             WrappedDataWatcher newWatcher = DisguiseUtilities | ||||
|                     .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), | ||||
|                             disguise.getWatcher()); | ||||
|             WrappedDataWatcher newWatcher = | ||||
|                     DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); | ||||
|  | ||||
|             if (NmsVersion.v1_15.isSupported()) { | ||||
|                 PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() | ||||
|                         .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), | ||||
|                                 newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true); | ||||
|                         .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), newWatcher, true) | ||||
|                         .createPacket(disguisedEntity.getEntityId(), newWatcher, true); | ||||
|  | ||||
|                 packets.addPacket(metaPacket); | ||||
|             } else { | ||||
| @@ -372,12 +359,11 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|                     entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType()); | ||||
|                 } | ||||
|  | ||||
|                 Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, | ||||
|                         loc.getPitch(), loc.getYaw(), entityType, data, | ||||
|                         ReflectionManager.getVec3D(disguisedEntity.getVelocity())}; | ||||
|                 Object[] params = | ||||
|                         new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, loc.getPitch(), loc.getYaw(), entityType, data, | ||||
|                                 ReflectionManager.getVec3D(disguisedEntity.getVelocity())}; | ||||
|  | ||||
|                 spawnEntity = ProtocolLibrary.getProtocolManager() | ||||
|                         .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params); | ||||
|                 spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params); | ||||
|             } else { | ||||
|                 int objectId = disguise.getType().getObjectId(); | ||||
|  | ||||
| @@ -387,8 +373,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|                 Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); | ||||
|  | ||||
|                 spawnEntity = ProtocolLibrary.getProtocolManager() | ||||
|                         .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data) | ||||
|                 spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data) | ||||
|                         .createPacket(nmsEntity, objectId, data); | ||||
|             } | ||||
|  | ||||
| @@ -448,7 +433,9 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|             packets.addPacket(newPacket); | ||||
|         } | ||||
|  | ||||
|         DisguiseUtilities.getNamePackets(disguise, new String[0]).forEach(packets::addPacket); | ||||
|         if (!disguise.isPlayerDisguise()) { | ||||
|             DisguiseUtilities.getNamePackets(disguise, new String[0]).forEach(packets::addPacket); | ||||
|         } | ||||
|  | ||||
|         // If armor must be sent because its currently not displayed and would've been sent normally | ||||
|  | ||||
| @@ -479,8 +466,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | ||||
|  | ||||
|                 if (NmsVersion.v1_16.isSupported()) { | ||||
|                     List<Pair<Object, Object>> list = new ArrayList<>(); | ||||
|                     list.add(Pair.of(ReflectionManager.createEnumItemSlot(slot), | ||||
|                             ReflectionManager.getNmsItem(itemToSend))); | ||||
|                     list.add(Pair.of(ReflectionManager.createEnumItemSlot(slot), ReflectionManager.getNmsItem(itemToSend))); | ||||
|  | ||||
|                     mods.write(1, list); | ||||
|                 } else { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user