mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-08-16 21:52:50 +02:00
Send the metadata to only the players who can see it
This commit is contained in:
parent
3e4a9b9f15
commit
a1ff8e6db9
|
@ -6,7 +6,7 @@ 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.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.comphenix.protocol.Packets;
|
import com.comphenix.protocol.Packets;
|
||||||
|
@ -15,6 +15,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||||
import net.minecraft.server.v1_6_R2.WatchableObject;
|
import net.minecraft.server.v1_6_R2.WatchableObject;
|
||||||
|
|
||||||
|
@ -30,15 +31,15 @@ public class FlagWatcher {
|
||||||
classTypes.put(ItemStack.class, 5);
|
classTypes.put(ItemStack.class, 5);
|
||||||
classTypes.put(ChunkCoordinates.class, 6);
|
classTypes.put(ChunkCoordinates.class, 6);
|
||||||
}
|
}
|
||||||
private int entityId;
|
private Disguise disguise;
|
||||||
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
|
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
|
||||||
|
|
||||||
protected FlagWatcher(int entityId) {
|
protected FlagWatcher(Disguise disguise) {
|
||||||
this.entityId = entityId;
|
this.disguise = disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlagWatcher clone() {
|
public FlagWatcher clone() {
|
||||||
FlagWatcher cloned = new FlagWatcher(entityId);
|
FlagWatcher cloned = new FlagWatcher(disguise);
|
||||||
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
@ -125,15 +126,17 @@ public class FlagWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendData(int data) {
|
protected void sendData(int data) {
|
||||||
|
Entity entity = disguise.getEntity();
|
||||||
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));
|
||||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, entityId);
|
mods.write(0, entity.getEntityId());
|
||||||
mods.write(1, list);
|
mods.write(1, list);
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (EntityPlayer player : disguise.getPerverts()) {
|
||||||
if (p.getEntityId() != entityId) {
|
Player p = player.getBukkitEntity();
|
||||||
|
if (p != entity) {
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user