From a1ff8e6db91dd1d546cfda705249fa77b26dcc0c Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 21 Jul 2013 15:15:28 +1200 Subject: [PATCH] Send the metadata to only the players who can see it --- .../disguise/DisguiseTypes/FlagWatcher.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java index 0ec3a385..7bfad4c6 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import com.comphenix.protocol.Packets; @@ -15,6 +15,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import net.minecraft.server.v1_6_R2.ChunkCoordinates; +import net.minecraft.server.v1_6_R2.EntityPlayer; import net.minecraft.server.v1_6_R2.ItemStack; import net.minecraft.server.v1_6_R2.WatchableObject; @@ -30,15 +31,15 @@ public class FlagWatcher { classTypes.put(ItemStack.class, 5); classTypes.put(ChunkCoordinates.class, 6); } - private int entityId; + private Disguise disguise; private HashMap entityValues = new HashMap(); - protected FlagWatcher(int entityId) { - this.entityId = entityId; + protected FlagWatcher(Disguise disguise) { + this.disguise = disguise; } public FlagWatcher clone() { - FlagWatcher cloned = new FlagWatcher(entityId); + FlagWatcher cloned = new FlagWatcher(disguise); cloned.entityValues = (HashMap) entityValues.clone(); return cloned; } @@ -125,15 +126,17 @@ public class FlagWatcher { } protected void sendData(int data) { + Entity entity = disguise.getEntity(); Object value = entityValues.get(data); List list = new ArrayList(); list.add(new WatchableObject(classTypes.get(value.getClass()), data, value)); PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); StructureModifier mods = packet.getModifier(); - mods.write(0, entityId); + mods.write(0, entity.getEntityId()); mods.write(1, list); - for (Player p : Bukkit.getOnlinePlayers()) { - if (p.getEntityId() != entityId) { + for (EntityPlayer player : disguise.getPerverts()) { + Player p = player.getBukkitEntity(); + if (p != entity) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); } catch (InvocationTargetException e) {