From fddbabf931a4a0f4db18adae3f0720617f450c1b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 24 Nov 2013 08:27:01 +1300 Subject: [PATCH] Add compatibility to flagwatcher for the new watchers --- .../disguise/disguisetypes/FlagWatcher.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 00cc13ae..3824126d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -49,6 +49,11 @@ public class FlagWatcher { this.disguise = disguise; } + @Override + protected Object clone() { + throw new RuntimeException("Please use clone(disguise) instead of clone()"); + } + public FlagWatcher clone(Disguise disguise) { FlagWatcher cloned = null; try { @@ -110,7 +115,7 @@ public class FlagWatcher { } } // Here we check for if there is a health packet that says they died. - if (disguise.isSelfDisguiseVisible() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) { + if (disguise.isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) { for (WrappedWatchableObject watch : newList) { // Its a health packet if (watch.getIndex() == 6) { @@ -119,7 +124,7 @@ public class FlagWatcher { float newHealth = (Float) value; if (newHealth > 0 && hasDied) { hasDied = false; - DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity()); + DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity()); } else if (newHealth <= 0 && !hasDied) { hasDied = true; } @@ -194,7 +199,7 @@ public class FlagWatcher { return; if (!entityValues.containsKey(data) || entityValues.get(data) == null) return; - Entity entity = disguise.getEntity(); + Entity entity = getDisguise().getEntity(); Object value = entityValues.get(data); List list = new ArrayList(); list.add(new WrappedWatchableObject(data, value)); @@ -202,7 +207,7 @@ public class FlagWatcher { StructureModifier mods = packet.getModifier(); mods.write(0, entity.getEntityId()); packet.getWatchableCollectionModifier().write(0, list); - for (Player player : disguise.getPerverts()) { + for (Player player : getDisguise().getPerverts()) { if (DisguiseAPI.isViewDisguises() || player != entity) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); @@ -251,7 +256,7 @@ public class FlagWatcher { if (itemStack == null) { // Find the item to replace it with if (disguise.getEntity() instanceof LivingEntity) { - EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment(); + EntityEquipment enquipment = ((LivingEntity) getDisguise().getEntity()).getEquipment(); if (slot == 0) { itemStack = enquipment.getItemInHand(); } else { @@ -273,11 +278,11 @@ public class FlagWatcher { slot = 0; PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT); StructureModifier mods = packet.getModifier(); - mods.write(0, disguise.getEntity().getEntityId()); + mods.write(0, getDisguise().getEntity().getEntityId()); mods.write(1, slot); mods.write(2, itemToSend); - for (Player player : disguise.getPerverts()) { - if (player != disguise.getEntity()) { + for (Player player : getDisguise().getPerverts()) { + if (player != getDisguise().getEntity()) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } catch (InvocationTargetException e) { @@ -312,6 +317,10 @@ public class FlagWatcher { sendData(0); } + protected Disguise getDisguise() { + return disguise; + } + protected void setValue(int no, Object value) { entityValues.put(no, value); }