From 1e12939d875ca7f1b2b326ba9d2d1880c8b5c373 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 23 May 2014 15:06:52 +1200 Subject: [PATCH] setMaxHealth now sends the packet as well --- .../disguisetypes/watchers/LivingWatcher.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index d22e582c..3841385a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -1,13 +1,27 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; + +import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.WrappedAttribute; +import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; + public class LivingWatcher extends FlagWatcher { static Object[] list; static Method potionNo; @@ -153,8 +167,27 @@ public class LivingWatcher extends FlagWatcher { public void setMaxHealth(double newHealth) { this.maxHealth = newHealth; - maxHealthSet = true; - // TODO Send packet + this.maxHealthSet = true; + if (getDisguise().getWatcher() != null && DisguiseAPI.isDisguiseInUse(getDisguise())) { + PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); + List attributes = new ArrayList(); + Builder builder; + builder = WrappedAttribute.newBuilder(); + builder.attributeKey("generic.maxHealth"); + builder.baseValue(getMaxHealth()); + builder.packet(packet); + attributes.add(builder.build()); + Entity entity = getDisguise().getEntity(); + packet.getIntegers().write(0, entity.getEntityId()); + packet.getAttributeCollectionModifier().write(0, attributes); + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } } }