[Bleeding] Implemented Vanish API.

Remove players that cannot see a player from their EntityTrackerEntry and only
send user list updates to players who can see the player they reference.

By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
CraftBukkit/Spigot 2012-01-31 13:54:15 -06:00
parent 994b74a0fd
commit f59f095728

View file

@ -11,22 +11,12 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.ChunkCoordinates; import net.minecraft.server.*;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.Packet131ItemData;
import net.minecraft.server.Packet200Statistic;
import net.minecraft.server.Packet201PlayerInfo;
import net.minecraft.server.Packet250CustomPayload;
import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet51MapChunk;
import net.minecraft.server.Packet53BlockChange;
import net.minecraft.server.Packet54PlayNoteBlock;
import net.minecraft.server.Packet61WorldEvent;
import net.minecraft.server.Packet6SpawnPosition;
import net.minecraft.server.Packet70Bed;
import net.minecraft.server.WorldServer;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.Achievement;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.CraftOfflinePlayer; import org.bukkit.craftbukkit.CraftOfflinePlayer;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
@ -46,6 +36,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private long lastPlayed = 0; private long lastPlayed = 0;
private boolean hasPlayedBefore = false; private boolean hasPlayedBefore = false;
private Set<String> channels = new HashSet<String>(); private Set<String> channels = new HashSet<String>();
private Set<Player> hiddenPlayers = new HashSet<Player>();
private int hash = 0; private int hash = 0;
public CraftPlayer(CraftServer server, EntityPlayer entity) { public CraftPlayer(CraftServer server, EntityPlayer entity) {
@ -162,8 +153,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().listName = name; getHandle().listName = name;
// Change the name on the client side // Change the name on the client side
server.getHandle().sendAll(new Packet201PlayerInfo(oldName, false, 9999)); Packet201PlayerInfo oldpacket = new Packet201PlayerInfo(oldName, false, 9999);
server.getHandle().sendAll(new Packet201PlayerInfo(name, true, getHandle().ping)); Packet201PlayerInfo packet = new Packet201PlayerInfo(name, true, getHandle().ping);
for (int i = 0; i < server.getHandle().players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) server.getHandle().players.get(i);
if (entityplayer.getBukkitEntity().canSee(this)) {
entityplayer.netServerHandler.sendPacket(oldpacket);
entityplayer.netServerHandler.sendPacket(packet);
}
}
} }
@Override @Override
@ -564,6 +563,38 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().spawnWorld = location.getWorld().getName(); getHandle().spawnWorld = location.getWorld().getName();
} }
public void hidePlayer(Player player) {
hiddenPlayers.add(player);
//remove this player from the hidden player's EntityTrackerEntry
EntityTracker tracker = ((WorldServer) entity.world).tracker;
EntityPlayer other = ((CraftPlayer) player).getHandle();
EntityTrackerEntry entry = (EntityTrackerEntry) tracker.trackedEntities.a(other.id);
if (entry != null) {
entry.c(getHandle());
}
//remove the hidden player from this player user list
getHandle().netServerHandler.sendPacket(new Packet201PlayerInfo(player.getPlayerListName(), false, 9999));
}
public void showPlayer(Player player) {
hiddenPlayers.remove(player);
EntityTracker tracker = ((WorldServer) entity.world).tracker;
EntityPlayer other = ((CraftPlayer) player).getHandle();
EntityTrackerEntry entry = (EntityTrackerEntry) tracker.trackedEntities.a(other.id);
if (entry != null && !entry.trackedPlayers.contains(getHandle())) {
entry.b(getHandle());
}
getHandle().netServerHandler.sendPacket(new Packet201PlayerInfo(player.getPlayerListName(), true, getHandle().ping));
}
public boolean canSee(Player player) {
return !hiddenPlayers.contains(player);
}
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>(); Map<String, Object> result = new LinkedHashMap<String, Object>();