From bff21ab039c42ed1bc77ba8a945a9399334e9a76 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 23 May 2014 16:51:00 +1200 Subject: [PATCH] Allow sendData of multiple data --- .../disguise/disguisetypes/FlagWatcher.java | 32 +++++++++++-------- .../watchers/TameableWatcher.java | 4 +-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 5a7dc6bb..79169d74 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -229,23 +229,27 @@ public class FlagWatcher { } } - protected void sendData(int data) { + protected void sendData(int... dataValues) { if (!DisguiseAPI.isDisguiseInUse(getDisguise())) return; - if (!entityValues.containsKey(data) || entityValues.get(data) == null) - return; - Object value = entityValues.get(data); List list = new ArrayList(); - list.add(new WrappedWatchableObject(data, value)); - PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); - StructureModifier mods = packet.getModifier(); - mods.write(0, getDisguise().getEntity().getEntityId()); - packet.getWatchableCollectionModifier().write(0, list); - for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); - } catch (InvocationTargetException e) { - e.printStackTrace(); + for (int data : dataValues) { + if (!entityValues.containsKey(data) || entityValues.get(data) == null) + continue; + Object value = entityValues.get(data); + list.add(new WrappedWatchableObject(data, value)); + } + if (!list.isEmpty()) { + PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + StructureModifier mods = packet.getModifier(); + mods.write(0, getDisguise().getEntity().getEntityId()); + packet.getWatchableCollectionModifier().write(0, list); + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index 2f1b7ee4..bdf45c63 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -42,8 +42,8 @@ public class TameableWatcher extends AgeableWatcher { @Override public void setHealth(float newHealth) { setValue(18, newHealth); - sendData(18); - super.setHealth(newHealth); + setValue(6, newHealth); + sendData(6, 18); } public void setOwner(String owner) {