Try fix armorstands option for player disguises

This commit is contained in:
libraryaddict 2021-01-15 23:24:46 +13:00
parent 7d2e59430d
commit bebadf9bc8
3 changed files with 49 additions and 41 deletions

View File

@ -153,6 +153,10 @@ public abstract class Disguise {
try { try {
for (Player player : DisguiseUtilities.getPerverts(this)) { for (Player player : DisguiseUtilities.getPerverts(this)) {
if (isPlayerDisguise() && LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) this)) {
continue;
}
for (PacketContainer packet : packets) { for (PacketContainer packet : packets) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} }

View File

@ -100,6 +100,16 @@ public class PlayerSkinHandler implements Listener {
}.runTaskTimer(LibsDisguises.getInstance(), 1, 1); }.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) { public PlayerSkin addPlayerSkin(Player player, PlayerDisguise disguise) {
tryProcess(player, false); tryProcess(player, false);
@ -335,6 +345,14 @@ public class PlayerSkinHandler implements Listener {
addMetadata(player, skin); 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()) { if (skin.isDoTabList()) {
PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);

View File

@ -52,13 +52,11 @@ public class PacketHandlerSpawn implements IPacketHandler {
@Override @Override
public PacketType[] getHandledPackets() { public PacketType[] getHandledPackets() {
return new PacketType[]{PacketType.Play.Server.NAMED_ENTITY_SPAWN, PacketType.Play.Server.SPAWN_ENTITY_LIVING, 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_EXPERIENCE_ORB, PacketType.Play.Server.SPAWN_ENTITY, PacketType.Play.Server.SPAWN_ENTITY_PAINTING};
PacketType.Play.Server.SPAWN_ENTITY_PAINTING};
} }
@Override @Override
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) {
packets.clear(); packets.clear();
@ -84,8 +82,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
} else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && } else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) {
disguisedEntity instanceof Damageable) {
builder.baseValue(((Damageable) disguisedEntity).getMaxHealth()); builder.baseValue(((Damageable) disguisedEntity).getMaxHealth());
} else { } else {
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
@ -104,8 +101,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
} }
} }
Location loc = disguisedEntity.getLocation().clone() Location loc = disguisedEntity.getLocation().clone().add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0);
.add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0);
Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null; Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null; Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
@ -169,8 +165,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
boolean visibleOrNewCompat = playerDisguise.isNameVisible() || DisguiseConfig.isScoreboardNames(); boolean visibleOrNewCompat = playerDisguise.isNameVisible() || DisguiseConfig.isScoreboardNames();
WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager
.getGameProfileWithThisSkin(UUID.randomUUID(), visibleOrNewCompat ? playerDisguise.getName() : "", .getGameProfileWithThisSkin(UUID.randomUUID(), visibleOrNewCompat ? playerDisguise.getName() : "", playerDisguise.getGameProfile());
playerDisguise.getGameProfile());
int entityId = disguisedEntity.getEntityId(); int entityId = disguisedEntity.getEntityId();
PlayerSkinHandler.PlayerSkin skin; PlayerSkinHandler.PlayerSkin skin;
@ -182,8 +177,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
// Add player to the list, necessary to spawn them // Add player to the list, necessary to spawn them
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0)); sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
List playerList = Collections List playerList = Collections.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), spawnProfile));
.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), spawnProfile));
sendTab.getModifier().write(1, playerList); sendTab.getModifier().write(1, playerList);
packets.addPacket(sendTab); packets.addPacket(sendTab);
@ -194,10 +188,8 @@ public class PacketHandlerSpawn implements IPacketHandler {
skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise); skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise);
if (LibsPremium.getPaidInformation() != null && if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
!LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()).add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT));
skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>())
.add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT));
} }
} else { } else {
skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise); 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 // If self disguise, or further than 50 blocks, or not in front of entity
boolean normalPlayerDisguise = observer == disguisedEntity || dist > (50 * 50) || boolean normalPlayerDisguise = observer == disguisedEntity || dist > (50 * 50) ||
(observer.getLocation().add(observer.getLocation().getDirection().normalize()) (observer.getLocation().add(observer.getLocation().getDirection().normalize()).distanceSquared(disguisedEntity.getLocation()) - dist) < 0.3;
.distanceSquared(disguisedEntity.getLocation()) - dist) < 0.3;
sendArmor = normalPlayerDisguise; sendArmor = normalPlayerDisguise;
skin.setSleepPackets(!normalPlayerDisguise); skin.setSleepPackets(!normalPlayerDisguise);
@ -239,20 +230,17 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (!normalPlayerDisguise) { if (!normalPlayerDisguise) {
toSend = new WrappedDataWatcher(); toSend = new WrappedDataWatcher();
WrappedDataWatcher.WrappedDataWatcherObject obj = WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32);
ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32);
// Set invis // Set invis
toSend.setObject(obj, (byte) 32); toSend.setObject(obj, (byte) 32);
} else { } else {
toSend = DisguiseUtilities toSend = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher());
} }
if (NmsVersion.v1_15.isSupported()) { if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket =
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true) ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true)
.createPacket(entityId, toSend, true); .createPacket(entityId, toSend, true);
packets.addPacket(metaPacket); packets.addPacket(metaPacket);
@ -315,14 +303,13 @@ public class PacketHandlerSpawn implements IPacketHandler {
mods.write(10, pitch); mods.write(10, pitch);
mods.write(11, yaw); mods.write(11, yaw);
WrappedDataWatcher newWatcher = DisguiseUtilities WrappedDataWatcher newWatcher =
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
disguise.getWatcher());
if (NmsVersion.v1_15.isSupported()) { if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), newWatcher, true)
newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true); .createPacket(disguisedEntity.getEntityId(), newWatcher, true);
packets.addPacket(metaPacket); packets.addPacket(metaPacket);
} else { } else {
@ -372,12 +359,11 @@ public class PacketHandlerSpawn implements IPacketHandler {
entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType()); entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
} }
Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, Object[] params =
loc.getPitch(), loc.getYaw(), entityType, data, new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, loc.getPitch(), loc.getYaw(), entityType, data,
ReflectionManager.getVec3D(disguisedEntity.getVelocity())}; ReflectionManager.getVec3D(disguisedEntity.getVelocity())};
spawnEntity = ProtocolLibrary.getProtocolManager() spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
} else { } else {
int objectId = disguise.getType().getObjectId(); int objectId = disguise.getType().getObjectId();
@ -387,8 +373,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
spawnEntity = ProtocolLibrary.getProtocolManager() spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
.createPacket(nmsEntity, objectId, data); .createPacket(nmsEntity, objectId, data);
} }
@ -448,7 +433,9 @@ public class PacketHandlerSpawn implements IPacketHandler {
packets.addPacket(newPacket); packets.addPacket(newPacket);
} }
if (!disguise.isPlayerDisguise()) {
DisguiseUtilities.getNamePackets(disguise, new String[0]).forEach(packets::addPacket); 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 // 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()) { if (NmsVersion.v1_16.isSupported()) {
List<Pair<Object, Object>> list = new ArrayList<>(); List<Pair<Object, Object>> list = new ArrayList<>();
list.add(Pair.of(ReflectionManager.createEnumItemSlot(slot), list.add(Pair.of(ReflectionManager.createEnumItemSlot(slot), ReflectionManager.getNmsItem(itemToSend)));
ReflectionManager.getNmsItem(itemToSend)));
mods.write(1, list); mods.write(1, list);
} else { } else {