Allow sendData of multiple data

This commit is contained in:
libraryaddict 2014-05-23 16:51:00 +12:00
parent 9e4ad0ba8e
commit bff21ab039
2 changed files with 20 additions and 16 deletions

View File

@ -229,23 +229,27 @@ public class FlagWatcher {
} }
} }
protected void sendData(int data) { protected void sendData(int... dataValues) {
if (!DisguiseAPI.isDisguiseInUse(getDisguise())) if (!DisguiseAPI.isDisguiseInUse(getDisguise()))
return; return;
if (!entityValues.containsKey(data) || entityValues.get(data) == null)
return;
Object value = entityValues.get(data);
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>(); List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
list.add(new WrappedWatchableObject(data, value)); for (int data : dataValues) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); if (!entityValues.containsKey(data) || entityValues.get(data) == null)
StructureModifier<Object> mods = packet.getModifier(); continue;
mods.write(0, getDisguise().getEntity().getEntityId()); Object value = entityValues.get(data);
packet.getWatchableCollectionModifier().write(0, list); list.add(new WrappedWatchableObject(data, value));
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { }
try { if (!list.isEmpty()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
} catch (InvocationTargetException e) { StructureModifier<Object> mods = packet.getModifier();
e.printStackTrace(); 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();
}
} }
} }
} }

View File

@ -42,8 +42,8 @@ public class TameableWatcher extends AgeableWatcher {
@Override @Override
public void setHealth(float newHealth) { public void setHealth(float newHealth) {
setValue(18, newHealth); setValue(18, newHealth);
sendData(18); setValue(6, newHealth);
super.setHealth(newHealth); sendData(6, 18);
} }
public void setOwner(String owner) { public void setOwner(String owner) {