From d4c657eee69c85a8b3b826f2714ed43dc4879e6a Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 Jul 2013 01:59:39 +1200 Subject: [PATCH] Change the packet sent for data to a packet container instead of CB packet --- .../disguise/DisguiseTypes/FlagWatcher.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java index 5ccd6fb9..662d744d 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java @@ -1,18 +1,21 @@ package me.libraryaddict.disguise.DisguiseTypes; -import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import com.comphenix.protocol.Packets; +import com.comphenix.protocol.ProtocolLibrary; +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.ItemStack; -import net.minecraft.server.v1_6_R2.Packet40EntityMetadata; import net.minecraft.server.v1_6_R2.WatchableObject; public class FlagWatcher { @@ -110,20 +113,21 @@ public class FlagWatcher { } protected void sendData(int data) { - Packet40EntityMetadata packet = new Packet40EntityMetadata(); - try { - packet.a = entityId; - Field field = Packet40EntityMetadata.class.getDeclaredField("b"); - field.setAccessible(true); - Object value = entityValues.get(data); - List list = new ArrayList(); - list.add(new WatchableObject(classTypes.get(value.getClass()), data, value)); - field.set(packet, list); - } catch (Exception ex) { - ex.printStackTrace(); - } + 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(1, list); for (Player p : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + if (p.getEntityId() != entityId) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } } }