[Bleeding] Handle players disconnecting during respawn. Fixes BUKKIT-4327

Prior to this commit, a player disconnected during a respawn event would
remain in memory. This causes a ghosting issue of players in the slot
count and player list, as well as a reference leak.

This commit avoids re-adding the player to the player list (and world) if
they are disconnected. This ensures that the remainder of the respawn
logic is completed as well as ensuring a duplicate player is not left on
the server.

This commit also saves the player's file at the end of the method if they
have been disconnected to ensure that their next login is accurate to the
respawn event's actions. A player that was revived and disconnected will
reconnect as revived.
This commit is contained in:
turt2live 2014-02-01 20:46:23 -07:00 committed by Wesley Wolfe
parent d7d81fa68f
commit c59ba98ae6

View file

@ -498,10 +498,14 @@ public abstract class PlayerList {
entityplayer1.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(chunkcoordinates1.x, chunkcoordinates1.y, chunkcoordinates1.z));
entityplayer1.playerConnection.sendPacket(new PacketPlayOutExperience(entityplayer1.exp, entityplayer1.expTotal, entityplayer1.expLevel));
this.b(entityplayer1, worldserver);
worldserver.getPlayerChunkMap().addPlayer(entityplayer1);
worldserver.addEntity(entityplayer1);
this.players.add(entityplayer1);
// CraftBukkit start - Added from changeDimension
// CraftBukkit start
// Don't re-add player to player list if disconnected
if (!entityplayer.playerConnection.isDisconnected()) {
worldserver.getPlayerChunkMap().addPlayer(entityplayer1);
worldserver.addEntity(entityplayer1);
this.players.add(entityplayer1);
}
// Added from changeDimension
this.updateClient(entityplayer1); // Update health, etc...
entityplayer1.updateAbilities();
Iterator iterator = entityplayer1.getEffects().iterator();
@ -515,11 +519,17 @@ public abstract class PlayerList {
// CraftBukkit end
entityplayer1.setHealth(entityplayer1.getHealth());
// CraftBukkit start - Don't fire on respawn
// CraftBukkit start
// Don't fire on respawn
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent((Player) entityplayer1.getBukkitEntity(), fromWorld);
Bukkit.getServer().getPluginManager().callEvent(event);
}
// Save player file again if they were disconnected
if (entityplayer.playerConnection.isDisconnected()) {
this.b(entityplayer1);
}
// CraftBukkit end
return entityplayer1;