From c59ba98ae6c61c78827a33a3138ade5462d9ae11 Mon Sep 17 00:00:00 2001 From: turt2live Date: Sat, 1 Feb 2014 20:46:23 -0700 Subject: [PATCH] [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. --- .../java/net/minecraft/server/PlayerList.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 534073b3ff..4383275396 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -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;