[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.
Dieser Commit ist enthalten in:
Ursprung
028cbb8fe9
Commit
37c8868532
@ -8,7 +8,7 @@ import java.util.Set;
|
|||||||
public class EntityTracker {
|
public class EntityTracker {
|
||||||
|
|
||||||
private Set a = new HashSet();
|
private Set a = new HashSet();
|
||||||
private IntHashMap trackedEntities = new IntHashMap();
|
public IntHashMap trackedEntities = new IntHashMap(); // CraftBukkit - private -> public
|
||||||
private MinecraftServer c;
|
private MinecraftServer c;
|
||||||
private int d;
|
private int d;
|
||||||
private World world; // CraftBukkit - change type
|
private World world; // CraftBukkit - change type
|
||||||
|
@ -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 (d0 >= (double) (-this.b) && d0 <= (double) this.b && d1 >= (double) (-this.b) && d1 <= (double) this.b) {
|
||||||
if (!this.trackedPlayers.contains(entityplayer)) {
|
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);
|
this.trackedPlayers.add(entityplayer);
|
||||||
entityplayer.netServerHandler.sendPacket(this.b());
|
entityplayer.netServerHandler.sendPacket(this.b());
|
||||||
if (this.isMoving) {
|
if (this.isMoving) {
|
||||||
|
@ -111,10 +111,8 @@ public class ServerConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void c(EntityPlayer entityplayer) {
|
public void c(EntityPlayer entityplayer) {
|
||||||
// CraftBukkit start
|
cserver.detectListNameConflict(entityplayer); // CraftBukkit
|
||||||
cserver.detectListNameConflict(entityplayer);
|
//this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, 1000)); // CraftBukkit - replaced with loop below
|
||||||
this.sendAll(new Packet201PlayerInfo(entityplayer.listName, true, 1000));
|
|
||||||
// CraftBukkit end
|
|
||||||
this.players.add(entityplayer);
|
this.players.add(entityplayer);
|
||||||
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
|
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
|
||||||
|
|
||||||
@ -142,11 +140,24 @@ public class ServerConfigurationManager {
|
|||||||
worldserver.addEntity(entityplayer);
|
worldserver.addEntity(entityplayer);
|
||||||
this.getPlayerManager(entityplayer.dimension).addPlayer(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) {
|
for (int i = 0; i < this.players.size(); ++i) {
|
||||||
EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
|
EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
|
||||||
|
|
||||||
// CraftBukkit start - .name -> .listName
|
// 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
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,8 +180,15 @@ public class ServerConfigurationManager {
|
|||||||
this.server.getWorldServer(entityplayer.dimension).kill(entityplayer);
|
this.server.getWorldServer(entityplayer.dimension).kill(entityplayer);
|
||||||
this.players.remove(entityplayer);
|
this.players.remove(entityplayer);
|
||||||
this.getPlayerManager(entityplayer.dimension).removePlayer(entityplayer);
|
this.getPlayerManager(entityplayer.dimension).removePlayer(entityplayer);
|
||||||
// CraftBukkit start - .name -> .listName
|
// CraftBukkit start - .name -> .listName, replace sendAll with loop
|
||||||
this.sendAll(new Packet201PlayerInfo(entityplayer.listName, false, 9999));
|
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
|
// CraftBukkit end
|
||||||
|
|
||||||
return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
||||||
|
@ -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>();
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren