From 21d4bba9f4df144ffc25cef6daf61baf5332583c Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 14 Jun 2014 21:11:37 +1200 Subject: [PATCH] Max health is now correctly set on entity spawn --- .../disguise/utilities/PacketsManager.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index fe7225bc..6e3742ea 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -28,6 +28,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Ageable; import org.bukkit.entity.Arrow; +import org.bukkit.entity.Damageable; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; @@ -145,6 +146,25 @@ public class PacketsManager { } } } + if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); + List attributes = new ArrayList(); + Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth"); + if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { + builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); + } else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) { + builder.baseValue(((Damageable) disguisedEntity).getMaxHealth()); + } else { + builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); + } + builder.packet(packet); + attributes.add(builder.build()); + packet.getIntegers().write(0, disguisedEntity.getEntityId()); + packet.getAttributeCollectionModifier().write(0, attributes); + packets.add(packet); + } + } PacketContainer[] spawnPackets = new PacketContainer[2 + packets.size()]; for (int i = 0; i < packets.size(); i++) { spawnPackets[i + 2] = packets.get(i);