diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-01-31 13:54:15 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-03 03:34:03 -0500 |
commit | 37c88685324165dad8692dae03014cbfeb119936 (patch) | |
tree | 1308b3ac34167b9116965227d45cf2d114666510 /src/main/java | |
parent | 028cbb8fe9f7b8062b1074aaeb63a9a62e34bf05 (diff) | |
download | craftbukkit-37c88685324165dad8692dae03014cbfeb119936.tar craftbukkit-37c88685324165dad8692dae03014cbfeb119936.tar.gz craftbukkit-37c88685324165dad8692dae03014cbfeb119936.tar.lz craftbukkit-37c88685324165dad8692dae03014cbfeb119936.tar.xz craftbukkit-37c88685324165dad8692dae03014cbfeb119936.zip |
[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.
Diffstat (limited to 'src/main/java')
4 files changed, 82 insertions, 25 deletions
diff --git a/src/main/java/net/minecraft/server/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java index 89eba263..93f95983 100644 --- a/src/main/java/net/minecraft/server/EntityTracker.java +++ b/src/main/java/net/minecraft/server/EntityTracker.java @@ -8,7 +8,7 @@ import java.util.Set; public class EntityTracker { private Set a = new HashSet(); - private IntHashMap trackedEntities = new IntHashMap(); + public IntHashMap trackedEntities = new IntHashMap(); // CraftBukkit - private -> public private MinecraftServer c; private int d; private World world; // CraftBukkit - change type diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java index caef4df7..6ccf0189 100644 --- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java +++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java @@ -187,6 +187,14 @@ public class EntityTrackerEntry { if (d0 >= (double) (-this.b) && d0 <= (double) this.b && d1 >= (double) (-this.b) && d1 <= (double) this.b) { if (!this.trackedPlayers.contains(entityplayer)) { + // CraftBukkit start + if (tracker instanceof EntityPlayer) { + org.bukkit.entity.Player player = ((EntityPlayer) tracker).getBukkitEntity(); + if (!entityplayer.getBukkitEntity().canSee(player)) { + return; + } + } + // CraftBukkit end this.trackedPlayers.add(entityplayer); entityplayer.netServerHandler.sendPacket(this.b()); if (this.isMoving) { diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index 271fb035..3cea43f1 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -111,10 +111,8 @@ public class ServerConfigurationManager { } public void c(EntityPlayer entityplayer) { - // CraftBukkit start - cserver.detectListNameConflict(entityplayer); - this.sendAll(new Packet201PlayerInfo(entityplayer.listName, true, 1000)); - // CraftBukkit end + cserver.detectListNameConflict(entityplayer); // CraftBukkit + //this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, 1000)); // CraftBukkit - replaced with loop below this.players.add(entityplayer); WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); @@ -142,11 +140,24 @@ public class ServerConfigurationManager { worldserver.addEntity(entityplayer); this.getPlayerManager(entityplayer.dimension).addPlayer(entityplayer); + // CraftBukkit start - sendAll above replaced with this loop + Packet201PlayerInfo packet = new Packet201PlayerInfo(entityplayer.listName, true, 1000); + for (int i = 0; i < this.players.size(); ++i) { + EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i); + + if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { + entityplayer1.netServerHandler.sendPacket(packet); + } + } + // CraftBukkit end + for (int i = 0; i < this.players.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i); // CraftBukkit start - .name -> .listName - entityplayer.netServerHandler.sendPacket(new Packet201PlayerInfo(entityplayer1.listName, true, entityplayer1.ping)); + if (entityplayer.getBukkitEntity().canSee(entityplayer1.getBukkitEntity())) { + entityplayer.netServerHandler.sendPacket(new Packet201PlayerInfo(entityplayer1.listName, true, entityplayer1.ping)); + } // CraftBukkit end } } @@ -169,8 +180,15 @@ public class ServerConfigurationManager { this.server.getWorldServer(entityplayer.dimension).kill(entityplayer); this.players.remove(entityplayer); this.getPlayerManager(entityplayer.dimension).removePlayer(entityplayer); - // CraftBukkit start - .name -> .listName - this.sendAll(new Packet201PlayerInfo(entityplayer.listName, false, 9999)); + // CraftBukkit start - .name -> .listName, replace sendAll with loop + Packet201PlayerInfo packet = new Packet201PlayerInfo(entityplayer.listName, false, 9999); + for (int i = 0; i < this.players.size(); ++i) { + EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i); + + if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { + entityplayer1.netServerHandler.sendPacket(packet); + } + } // CraftBukkit end return playerQuitEvent.getQuitMessage(); // CraftBukkit diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 6aa39bca..e9172637 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -11,22 +11,12 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.ChunkCoordinates; -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 net.minecraft.server.*; 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.craftbukkit.CraftOfflinePlayer; import org.bukkit.craftbukkit.CraftServer; @@ -46,6 +36,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private long lastPlayed = 0; private boolean hasPlayedBefore = false; private Set<String> channels = new HashSet<String>(); + private Set<Player> hiddenPlayers = new HashSet<Player>(); private int hash = 0; public CraftPlayer(CraftServer server, EntityPlayer entity) { @@ -162,8 +153,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().listName = name; // Change the name on the client side - server.getHandle().sendAll(new Packet201PlayerInfo(oldName, false, 9999)); - server.getHandle().sendAll(new Packet201PlayerInfo(name, true, getHandle().ping)); + Packet201PlayerInfo oldpacket = new Packet201PlayerInfo(oldName, false, 9999); + 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 @@ -564,6 +563,38 @@ public class CraftPlayer extends CraftHumanEntity implements Player { 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() { Map<String, Object> result = new LinkedHashMap<String, Object>(); |