Change the packet sent for data to a packet container instead of CB packet

This commit is contained in:
Andrew 2013-07-12 01:59:39 +12:00
parent 8ca7f25b4a
commit d4c657eee6

View File

@ -1,18 +1,21 @@
package me.libraryaddict.disguise.DisguiseTypes; package me.libraryaddict.disguise.DisguiseTypes;
import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
import org.bukkit.entity.Player; 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.ChunkCoordinates;
import net.minecraft.server.v1_6_R2.ItemStack; import net.minecraft.server.v1_6_R2.ItemStack;
import net.minecraft.server.v1_6_R2.Packet40EntityMetadata;
import net.minecraft.server.v1_6_R2.WatchableObject; import net.minecraft.server.v1_6_R2.WatchableObject;
public class FlagWatcher { public class FlagWatcher {
@ -110,20 +113,21 @@ public class FlagWatcher {
} }
protected void sendData(int data) { 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); Object value = entityValues.get(data);
List<WatchableObject> list = new ArrayList<WatchableObject>(); List<WatchableObject> list = new ArrayList<WatchableObject>();
list.add(new WatchableObject(classTypes.get(value.getClass()), data, value)); list.add(new WatchableObject(classTypes.get(value.getClass()), data, value));
field.set(packet, list); PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
} catch (Exception ex) { StructureModifier<Object> mods = packet.getModifier();
ex.printStackTrace(); mods.write(0, entityId);
} mods.write(1, list);
for (Player p : Bukkit.getOnlinePlayers()) { 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();
}
}
} }
} }