Fix armor not being displayed if its not delayed

This commit is contained in:
libraryaddict 2017-06-27 14:53:10 +12:00
parent 23c012d0e3
commit 80d416a4fc
2 changed files with 65 additions and 57 deletions

View File

@ -152,7 +152,8 @@ public class FlagWatcher {
} }
} }
// Here we check for if there is a health packet that says they died. // Here we check for if there is a health packet that says they died.
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) { if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise()
.getEntity() instanceof Player) {
for (WrappedWatchableObject watch : newList) { for (WrappedWatchableObject watch : newList) {
// Its a health packet // Its a health packet
if (watch.getIndex() == 6) { if (watch.getIndex() == 6) {
@ -164,8 +165,8 @@ public class FlagWatcher {
if (newHealth > 0 && hasDied) { if (newHealth > 0 && hasDied) {
hasDied = false; hasDied = false;
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), Bukkit.getScheduler()
new Runnable() { .scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@ -328,7 +329,8 @@ public class FlagWatcher {
Object value = entityValues.get(data.getIndex()); Object value = entityValues.get(data.getIndex());
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == MetaIndex.ENTITY_META) { if (isEntityAnimationsAdded() && DisguiseConfig
.isMetadataPacketsEnabled() && data == MetaIndex.ENTITY_META) {
value = addEntityAnimations((byte) value, value = addEntityAnimations((byte) value,
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
} }
@ -449,13 +451,11 @@ public class FlagWatcher {
public void setItemStack(EquipmentSlot slot, ItemStack itemStack) { public void setItemStack(EquipmentSlot slot, ItemStack itemStack) {
equipment.setItem(slot, itemStack); equipment.setItem(slot, itemStack);
sendItemStack(slot, itemStack);
} }
protected void sendItemStack(EquipmentSlot slot, ItemStack itemStack) { protected void sendItemStack(EquipmentSlot slot, ItemStack itemStack) {
if (!DisguiseAPI.isDisguiseInUse( if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this || getDisguise()
getDisguise()) || getDisguise().getWatcher() != this || getDisguise().getEntity() == null) .getEntity() == null)
return; return;
if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) { if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) {
@ -496,7 +496,6 @@ public class FlagWatcher {
mods.write(2, itemToSend); mods.write(2, itemToSend);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} }

View File

@ -57,8 +57,8 @@ import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerViewDis
public class PacketsManager { public class PacketsManager {
public static class LibsPackets { public static class LibsPackets {
private ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>(); private ArrayList<PacketContainer> packets = new ArrayList<>();
private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<Integer, ArrayList<PacketContainer>>(); private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>();
private boolean isSpawnPacket; private boolean isSpawnPacket;
private Disguise disguise; private Disguise disguise;
private boolean doNothing; private boolean doNothing;
@ -140,9 +140,8 @@ public class PacketsManager {
private static PacketListener soundsListener; private static PacketListener soundsListener;
private static boolean soundsListenerEnabled; private static boolean soundsListenerEnabled;
private static PacketListener viewDisguisesListener; private static PacketListener viewDisguisesListener;
private static PacketListener tabListListener;
private static boolean viewDisguisesListenerEnabled; private static boolean viewDisguisesListenerEnabled;
private static HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<Disguise, ArrayList<UUID>>(); private static HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<>();
public static void addPacketListeners() { public static void addPacketListeners() {
// Add a client listener to cancel them interacting with uninteractable disguised entitys. // Add a client listener to cancel them interacting with uninteractable disguised entitys.
@ -150,7 +149,7 @@ public class PacketsManager {
// Because it kicks you for hacking. // Because it kicks you for hacking.
clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises); clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises);
tabListListener = new PacketListenerTabList(libsDisguises); PacketListener tabListListener = new PacketListenerTabList(libsDisguises);
ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener); ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener);
ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener); ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener);
@ -194,14 +193,12 @@ public class PacketsManager {
continue; continue;
} }
ItemStack item = null;
if (disguisedEntity instanceof LivingEntity) { if (disguisedEntity instanceof LivingEntity) {
item = ReflectionManager.getEquipment(slot, disguisedEntity); ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity);
}
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
continue; continue;
}
} }
PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT); PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT);
@ -212,20 +209,21 @@ public class PacketsManager {
mods.write(1, ReflectionManager.createEnumItemSlot(slot)); mods.write(1, ReflectionManager.createEnumItemSlot(slot));
mods.write(2, ReflectionManager.getNmsItem(itemstack)); mods.write(2, ReflectionManager.getNmsItem(itemstack));
packets.addPacket(packet); packets.addDelayedPacket(packet);
} }
} }
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
if (disguise.getWatcher() instanceof LivingWatcher) { if (disguise.getWatcher() instanceof LivingWatcher) {
ArrayList<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>(); ArrayList<WrappedAttribute> attributes = new ArrayList<>();
Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth"); Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth");
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() && disguisedEntity instanceof Damageable) { } else if (DisguiseConfig
.isMaxHealthDeterminedByDisguisedEntity() && 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());
@ -348,9 +346,9 @@ public class PacketsManager {
spawnPlayer.getDataWatcherModifier().write(0, newWatcher); spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
// Make him invisible // Make him invisible
newWatcher.setObject( newWatcher
new WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), Registry.get(Byte.class)), .setObject(new WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), Registry.get(Byte.class)),
(byte) 32); (byte) 32);
packets.addPacket(spawnPlayer); packets.addPacket(spawnPlayer);
@ -462,9 +460,9 @@ public class PacketsManager {
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor( PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data).createPacket(nmsEntity, objectId, .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
data); .createPacket(nmsEntity, objectId, data);
packets.addPacket(spawnEntity); packets.addPacket(spawnEntity);
spawnEntity.getModifier().write(8, pitch); spawnEntity.getModifier().write(8, pitch);
@ -509,8 +507,9 @@ public class PacketsManager {
WrappedDataWatcher newWatcher = new WrappedDataWatcher(); WrappedDataWatcher newWatcher = new WrappedDataWatcher();
try { try {
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert( List<WrappedWatchableObject> list =
watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects(); DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher.getWatchableObjects()) :
flagWatcher.getWatchableObjects();
for (WrappedWatchableObject watchableObject : list) { for (WrappedWatchableObject watchableObject : list) {
if (watchableObject == null) if (watchableObject == null)
@ -637,7 +636,8 @@ public class PacketsManager {
public static double getYModifier(Entity entity, Disguise disguise) { public static double getYModifier(Entity entity, Disguise disguise) {
double yMod = 0; double yMod = 0;
if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) && entity.getType() == EntityType.DROPPED_ITEM) { if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher())
.isSleeping()) && entity.getType() == EntityType.DROPPED_ITEM) {
yMod -= 0.13; yMod -= 0.13;
} }
@ -742,7 +742,8 @@ public class PacketsManager {
Disguise disguise = DisguiseAPI.getDisguise(player, player); Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise != null) { if (disguise != null) {
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && (disguise
.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
player.updateInventory(); player.updateInventory();
} }
} }
@ -756,7 +757,7 @@ public class PacketsManager {
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener); ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
} }
ArrayList<PacketType> packetsToListen = new ArrayList<PacketType>(); ArrayList<PacketType> packetsToListen = new ArrayList<>();
// Add spawn packets // Add spawn packets
{ {
packetsToListen.add(Server.NAMED_ENTITY_SPAWN); packetsToListen.add(Server.NAMED_ENTITY_SPAWN);
@ -835,7 +836,8 @@ public class PacketsManager {
DisguiseUtilities.removeSelfDisguise(player); DisguiseUtilities.removeSelfDisguise(player);
} }
if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise
.isHidingHeldItemFromSelf())) {
player.updateInventory(); player.updateInventory();
} }
} }
@ -903,10 +905,10 @@ public class PacketsManager {
else if (sentPacket.getType() == Server.ENTITY_METADATA) { else if (sentPacket.getType() == Server.ENTITY_METADATA) {
packets.clear(); packets.clear();
if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) || !cancelMeta.get( if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) || !cancelMeta
disguise).contains(observer.getUniqueId()))) { .get(disguise).contains(observer.getUniqueId()))) {
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
sentPacket.getWatchableCollectionModifier().read(0)); .convert(sentPacket.getWatchableCollectionModifier().read(0));
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA); PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
@ -921,7 +923,10 @@ public class PacketsManager {
} }
// Else if the packet is spawning.. // Else if the packet is spawning..
else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING || sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == Server.SPAWN_ENTITY || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) { else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket
.getType() == Server.SPAWN_ENTITY_LIVING || sentPacket
.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket
.getType() == Server.SPAWN_ENTITY || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) {
packets.clear(); packets.clear();
constructSpawnPackets(observer, packets, entity); constructSpawnPackets(observer, packets, entity);
@ -929,8 +934,9 @@ public class PacketsManager {
// Else if the disguise is attempting to send players a forbidden packet // Else if the disguise is attempting to send players a forbidden packet
else if (sentPacket.getType() == Server.ANIMATION) { else if (sentPacket.getType() == Server.ANIMATION) {
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read( if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType()
1) == 2 && (!disguise.getType().isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) { .isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher())
.isSleeping())))) {
packets.clear(); packets.clear();
} }
} }
@ -939,7 +945,8 @@ public class PacketsManager {
else if (sentPacket.getType() == Server.COLLECT) { else if (sentPacket.getType() == Server.COLLECT) {
if (disguise.getType().isMisc()) { if (disguise.getType().isMisc()) {
packets.clear(); packets.clear();
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType()
.isPlayer() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
PacketContainer newPacket = new PacketContainer(Server.ANIMATION); PacketContainer newPacket = new PacketContainer(Server.ANIMATION);
StructureModifier<Integer> mods = newPacket.getIntegers(); StructureModifier<Integer> mods = newPacket.getIntegers();
@ -954,16 +961,17 @@ public class PacketsManager {
} }
// Else if the disguise is moving. // Else if the disguise is moving.
else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket.getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.REL_ENTITY_MOVE) { else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { .getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket
.getType() == Server.REL_ENTITY_MOVE) {
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket
.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) {
// Rabbit robbing... // Rabbit robbing...
if (entity.getMetadata( if (entity.getMetadata("LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity
"LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity.getMetadata( .getMetadata("LibsRabbitHop").get(0).asLong() < 100 || System.currentTimeMillis() - entity
"LibsRabbitHop").get(0).asLong() < 100 || System.currentTimeMillis() - entity.getMetadata( .getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
"LibsRabbitHop").get(0).asLong() > 500) { if (entity.getMetadata("LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity
if (entity.getMetadata( .getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
"LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity.getMetadata(
"LibsRabbitHop").get(0).asLong() > 500) {
entity.removeMetadata("LibsRabbitHop", libsDisguises); entity.removeMetadata("LibsRabbitHop", libsDisguises);
entity.setMetadata("LibsRabbitHop", entity.setMetadata("LibsRabbitHop",
new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
@ -995,7 +1003,8 @@ public class PacketsManager {
bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue)); bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue));
bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) { if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise
.getType() == DisguiseType.ITEM_FRAME) {
StructureModifier<Double> doubles = movePacket.getDoubles(); StructureModifier<Double> doubles = movePacket.getDoubles();
Location loc = entity.getLocation(); Location loc = entity.getLocation();
@ -1021,8 +1030,8 @@ public class PacketsManager {
// Else if the disguise is updating equipment // Else if the disguise is updating equipment
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) { else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) {
EquipmentSlot slot = ReflectionManager.createEquipmentSlot( EquipmentSlot slot = ReflectionManager
packets.getPackets().get(0).getModifier().read(1)); .createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot); org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
@ -1045,8 +1054,8 @@ public class PacketsManager {
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetadataPacketsEnabled()) { if (DisguiseConfig.isMetadataPacketsEnabled()) {
WrappedWatchableObject watch = ReflectionManager.createWatchable(0, WrappedWatchableObject watch = ReflectionManager
WrappedDataWatcher.getEntityWatcher(entity).getByte(0)); .createWatchable(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
list.add(watch); list.add(watch);