--- a/net/minecraft/server/PlayerList.java +++ b/net/minecraft/server/PlayerList.java @@ -19,6 +19,29 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// CraftBukkit start +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.TravelAgent; +import org.bukkit.craftbukkit.util.CraftChatMessage; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.util.Vector; +// CraftBukkit end + public abstract class PlayerList { public static final File a = new File("banned-players.json"); @@ -28,14 +51,16 @@ private static final Logger f = LogManager.getLogger(); private static final SimpleDateFormat g = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); private final MinecraftServer server; - public final List players = Lists.newArrayList(); + public final List players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety private final Map j = Maps.newHashMap(); private final GameProfileBanList k; private final IpBanList l; private final OpList operators; private final WhiteList whitelist; - private final Map o; - private final Map p; + // CraftBukkit start + // private final Map o; + // private final Map p; + // CraftBukkit end public IPlayerFileData playerFileData; private boolean hasWhitelist; protected int maxPlayers; @@ -44,13 +69,23 @@ private boolean u; private int v; + // CraftBukkit start + private CraftServer cserver; + public PlayerList(MinecraftServer minecraftserver) { + this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this); + minecraftserver.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance(); + minecraftserver.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(minecraftserver.server)); + // CraftBukkit end + this.k = new GameProfileBanList(PlayerList.a); this.l = new IpBanList(PlayerList.b); this.operators = new OpList(PlayerList.c); this.whitelist = new WhiteList(PlayerList.d); - this.o = Maps.newHashMap(); - this.p = Maps.newHashMap(); + // CraftBukkit start + // this.o = Maps.newHashMap(); + // this.p = Maps.newHashMap(); + // CraftBukkit end this.server = minecraftserver; this.k.a(false); this.l.a(false); @@ -65,6 +100,12 @@ usercache.a(gameprofile); NBTTagCompound nbttagcompound = this.a(entityplayer); + // CraftBukkit start - Better rename detection + if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) { + NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit"); + s = bukkit.hasKeyOfType("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s; + } + // CraftBukkit end entityplayer.spawnIn(this.server.getWorldServer(entityplayer.dimension)); entityplayer.playerInteractManager.a((WorldServer) entityplayer.world); @@ -74,7 +115,8 @@ s1 = networkmanager.getSocketAddress().toString(); } - PlayerList.f.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getName(), s1, Integer.valueOf(entityplayer.getId()), Double.valueOf(entityplayer.locX), Double.valueOf(entityplayer.locY), Double.valueOf(entityplayer.locZ)); + // CraftBukkit - Moved message to after join + // PlayerList.f.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getName(), s1, Integer.valueOf(entityplayer.getId()), Double.valueOf(entityplayer.locX), Double.valueOf(entityplayer.locY), Double.valueOf(entityplayer.locZ)); WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); WorldData worlddata = worldserver.getWorldData(); @@ -82,6 +124,7 @@ PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer); playerconnection.sendPacket(new PacketPlayOutLogin(entityplayer.getId(), entityplayer.playerInteractManager.getGameMode(), worlddata.isHardcore(), worldserver.worldProvider.getDimensionManager().getDimensionID(), worldserver.getDifficulty(), this.getMaxPlayers(), worlddata.getType(), worldserver.getGameRules().getBoolean("reducedDebugInfo"))); + entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit playerconnection.sendPacket(new PacketPlayOutCustomPayload("MC|Brand", (new PacketDataSerializer(Unpooled.buffer())).a(this.getServer().getServerModName()))); playerconnection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); playerconnection.sendPacket(new PacketPlayOutAbilities(entityplayer.abilities)); @@ -91,17 +134,23 @@ entityplayer.F().a(entityplayer); this.sendScoreboard((ScoreboardServer) worldserver.getScoreboard(), entityplayer); this.server.aD(); - ChatMessage chatmessage; + // CraftBukkit start - login message is handled in the event + // ChatMessage chatmessage; + String joinMessage; if (entityplayer.getName().equalsIgnoreCase(s)) { - chatmessage = new ChatMessage("multiplayer.player.joined", new Object[] { entityplayer.getScoreboardDisplayName()}); + // chatmessage = new ChatMessage("multiplayer.player.joined", new Object[] { entityplayer.getScoreboardDisplayName()}); + joinMessage = "\u00A7e" + LocaleI18n.a("multiplayer.player.joined", entityplayer.getName()); } else { - chatmessage = new ChatMessage("multiplayer.player.joined.renamed", new Object[] { entityplayer.getScoreboardDisplayName(), s}); + // chatmessage = new ChatMessage("multiplayer.player.joined.renamed", new Object[] { entityplayer.getScoreboardDisplayName(), s}); + joinMessage = "\u00A7e" + LocaleI18n.a("multiplayer.player.joined.renamed", entityplayer.getName(), s); } - chatmessage.getChatModifier().setColor(EnumChatFormat.YELLOW); - this.sendMessage(chatmessage); - this.onPlayerJoin(entityplayer); + // chatmessage.getChatModifier().setColor(EnumChatFormat.YELLOW); + // this.sendMessage(chatmessage); + this.onPlayerJoin(entityplayer, joinMessage); + // CraftBukkit end + worldserver = server.getWorldServer(entityplayer.dimension); // CraftBukkit - Update in case join event changed it playerconnection.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch); this.b(entityplayer, worldserver); if (!this.server.getResourcePack().isEmpty()) { @@ -153,6 +202,8 @@ } entityplayer.syncInventory(); + // CraftBukkit - Moved from above, added world + PlayerList.f.info(entityplayer.getName() + "[" + s1 + "] logged in with entity id " + entityplayer.getId() + " at ([" + entityplayer.world.worldData.getName() + "]" + entityplayer.locX + ", " + entityplayer.locY + ", " + entityplayer.locZ + ")"); } public void sendScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) { @@ -185,26 +236,27 @@ } public void setPlayerFileData(WorldServer[] aworldserver) { + if (playerFileData != null) return; // CraftBukkit this.playerFileData = aworldserver[0].getDataManager().getPlayerFileData(); aworldserver[0].getWorldBorder().a(new IWorldBorderListener() { public void a(WorldBorder worldborder, double d0) { - PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_SIZE)); + PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_SIZE), worldborder.world); } public void a(WorldBorder worldborder, double d0, double d1, long i) { - PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.LERP_SIZE)); + PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.LERP_SIZE), worldborder.world); } public void a(WorldBorder worldborder, double d0, double d1) { - PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_CENTER)); + PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_CENTER), worldborder.world); } public void a(WorldBorder worldborder, int i) { - PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_TIME)); + PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_TIME), worldborder.world); } public void b(WorldBorder worldborder, int i) { - PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS)); + PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS), worldborder.world); } public void b(WorldBorder worldborder, double d0) {} @@ -237,7 +289,7 @@ @Nullable public NBTTagCompound a(EntityPlayer entityplayer) { - NBTTagCompound nbttagcompound = this.server.worldServer[0].getWorldData().h(); + NBTTagCompound nbttagcompound = this.server.worlds.get(0).getWorldData().h(); // CraftBukkit NBTTagCompound nbttagcompound1; if (entityplayer.getName().equals(this.server.Q()) && nbttagcompound != null) { @@ -253,13 +305,13 @@ protected void savePlayerFile(EntityPlayer entityplayer) { this.playerFileData.save(entityplayer); - ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.o.get(entityplayer.getUniqueID()); + ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit if (serverstatisticmanager != null) { serverstatisticmanager.b(); } - AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(entityplayer.getUniqueID()); + AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit if (advancementdataplayer != null) { advancementdataplayer.c(); @@ -267,28 +319,79 @@ } - public void onPlayerJoin(EntityPlayer entityplayer) { + public void onPlayerJoin(EntityPlayer entityplayer, String joinMessage) { // CraftBukkit added param this.players.add(entityplayer); this.j.put(entityplayer.getUniqueID(), entityplayer); - this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer})); + // this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer})); // CraftBukkit - replaced with loop below WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); + // CraftBukkit start + PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(cserver.getPlayer(entityplayer), joinMessage); + cserver.getPluginManager().callEvent(playerJoinEvent); + + if (!entityplayer.playerConnection.networkManager.isConnected()) { + return; + } + + joinMessage = playerJoinEvent.getJoinMessage(); + + if (joinMessage != null && joinMessage.length() > 0) { + for (IChatBaseComponent line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) { + server.getPlayerList().sendAll(new PacketPlayOutChat(line)); + } + } + + ChunkIOExecutor.adjustPoolSize(getPlayerCount()); + // CraftBukkit end + + // CraftBukkit start - sendAll above replaced with this loop + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityplayer); + for (int i = 0; i < this.players.size(); ++i) { - entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { (EntityPlayer) this.players.get(i)})); + EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i); + + if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { + entityplayer1.playerConnection.sendPacket(packet); + } + + if (!entityplayer.getBukkitEntity().canSee(entityplayer1.getBukkitEntity())) { + continue; + } + + entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer1})); } + entityplayer.sentListPacket = true; + // CraftBukkit end + + entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityplayer.getId(), entityplayer.datawatcher, true)); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn - worldserver.addEntity(entityplayer); - this.a(entityplayer, (WorldServer) null); + // CraftBukkit start - Only add if the player wasn't moved in the event + if (entityplayer.world == worldserver && !worldserver.players.contains(entityplayer)) { + worldserver.addEntity(entityplayer); + this.a(entityplayer, (WorldServer) null); + } + // CraftBukkit end } public void d(EntityPlayer entityplayer) { entityplayer.x().getPlayerChunkMap().movePlayer(entityplayer); } - public void disconnect(EntityPlayer entityplayer) { + public String disconnect(EntityPlayer entityplayer) { // CraftBukkit - return string WorldServer worldserver = entityplayer.x(); entityplayer.b(StatisticList.f); + + // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it + org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer); + + PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game"); + cserver.getPluginManager().callEvent(playerQuitEvent); + entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); + + entityplayer.playerTick();// SPIGOT-924 + // CraftBukkit end + this.savePlayerFile(entityplayer); if (entityplayer.isPassenger()) { Entity entity = entityplayer.getVehicle(); @@ -318,17 +421,67 @@ if (entityplayer1 == entityplayer) { this.j.remove(uuid); - this.o.remove(uuid); - this.p.remove(uuid); + // CraftBukkit start + // this.o.remove(uuid); + // this.p.remove(uuid); + // CraftBukkit end } - this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer})); + // CraftBukkit start + // this.sendAll(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer})); + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityplayer); + for (int i = 0; i < players.size(); i++) { + EntityPlayer entityplayer2 = (EntityPlayer) this.players.get(i); + + if (entityplayer2.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { + entityplayer2.playerConnection.sendPacket(packet); + } else { + entityplayer2.getBukkitEntity().removeDisconnectingPlayer(entityplayer.getBukkitEntity()); + } + } + // This removes the scoreboard (and player reference) for the specific player in the manager + cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity()); + // CraftBukkit end + + ChunkIOExecutor.adjustPoolSize(this.getPlayerCount()); // CraftBukkit + + return playerQuitEvent.getQuitMessage(); // CraftBukkit } - public String attemptLogin(SocketAddress socketaddress, GameProfile gameprofile) { + // CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer + public EntityPlayer attemptLogin(LoginListener loginlistener, GameProfile gameprofile, String hostname) { + // Moved from processLogin + UUID uuid = EntityHuman.a(gameprofile); + ArrayList arraylist = Lists.newArrayList(); + + EntityPlayer entityplayer; + + for (int i = 0; i < this.players.size(); ++i) { + entityplayer = (EntityPlayer) this.players.get(i); + if (entityplayer.getUniqueID().equals(uuid)) { + arraylist.add(entityplayer); + } + } + + Iterator iterator = arraylist.iterator(); + + while (iterator.hasNext()) { + entityplayer = (EntityPlayer) iterator.next(); + savePlayerFile(entityplayer); // CraftBukkit - Force the player's inventory to be saved + entityplayer.playerConnection.disconnect(new ChatMessage("multiplayer.disconnect.duplicate_login", new Object[0])); + } + + // Instead of kicking then returning, we need to store the kick reason + // in the event, check with plugins to see if it's ok, and THEN kick + // depending on the outcome. + SocketAddress socketaddress = loginlistener.networkManager.getSocketAddress(); + + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), gameprofile, new PlayerInteractManager(server.getWorldServer(0))); + Player player = entity.getBukkitEntity(); + PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress()); String s; - if (this.k.isBanned(gameprofile)) { + if (getProfileBans().isBanned(gameprofile) && !getProfileBans().get(gameprofile).hasExpired()) { GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.k.get(gameprofile); s = "You are banned from this server!\nReason: " + gameprofilebanentry.getReason(); @@ -336,10 +489,12 @@ s = s + "\nYour ban will be removed on " + PlayerList.g.format(gameprofilebanentry.getExpires()); } - return s; + // return s; + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s); } else if (!this.isWhitelisted(gameprofile)) { - return "You are not white-listed on this server!"; - } else if (this.l.isBanned(socketaddress)) { + // return "You are not white-listed on this server!"; + event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "You are not white-listed on this server!"); + } else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) { IpBanEntry ipbanentry = this.l.get(socketaddress); s = "Your IP address is banned from this server!\nReason: " + ipbanentry.getReason(); @@ -347,13 +502,25 @@ s = s + "\nYour ban will be removed on " + PlayerList.g.format(ipbanentry.getExpires()); } - return s; + // return s; + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s); } else { - return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? "The server is full!" : null; + // return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? "The server is full!" : null; + if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) { + event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full"); + } } + + cserver.getPluginManager().callEvent(event); + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + loginlistener.disconnect(event.getKickMessage()); + return null; + } + return entity; } - public EntityPlayer processLogin(GameProfile gameprofile) { + public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer + /* CraftBukkit startMoved up UUID uuid = EntityHuman.a(gameprofile); ArrayList arraylist = Lists.newArrayList(); @@ -388,17 +555,27 @@ } return new EntityPlayer(this.server, this.server.getWorldServer(0), gameprofile, (PlayerInteractManager) object); + */ + return player; + // CraftBukkit end } + // CraftBukkit start public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag) { + return this.moveToWorld(entityplayer, i, flag, null, true); + } + + public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag, Location location, boolean avoidSuffocation) { + entityplayer.stopRiding(); // CraftBukkit entityplayer.x().getTracker().untrackPlayer(entityplayer); - entityplayer.x().getTracker().untrackEntity(entityplayer); + // entityplayer.x().getTracker().untrackEntity(entityplayer); // CraftBukkit entityplayer.x().getPlayerChunkMap().removePlayer(entityplayer); this.players.remove(entityplayer); this.server.getWorldServer(entityplayer.dimension).removeEntity(entityplayer); BlockPosition blockposition = entityplayer.getBed(); boolean flag1 = entityplayer.isRespawnForced(); + /* CraftBukkit start entityplayer.dimension = i; Object object; @@ -409,6 +586,11 @@ } EntityPlayer entityplayer1 = new EntityPlayer(this.server, this.server.getWorldServer(entityplayer.dimension), entityplayer.getProfile(), (PlayerInteractManager) object); + // */ + EntityPlayer entityplayer1 = entityplayer; + org.bukkit.World fromWorld = entityplayer.getBukkitEntity().getWorld(); + entityplayer.viewingCredits = false; + // CraftBukkit end entityplayer1.playerConnection = entityplayer.playerConnection; entityplayer1.copyFrom(entityplayer, flag); @@ -423,43 +605,163 @@ entityplayer1.addScoreboardTag(s); } - WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); + // WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); // CraftBukkit - handled later - this.a(entityplayer1, entityplayer, worldserver); + // this.a(entityplayer1, entityplayer, worldserver); // CraftBukkit - removed BlockPosition blockposition1; - if (blockposition != null) { - blockposition1 = EntityHuman.getBed(this.server.getWorldServer(entityplayer.dimension), blockposition, flag1); - if (blockposition1 != null) { - entityplayer1.setPositionRotation((double) ((float) blockposition1.getX() + 0.5F), (double) ((float) blockposition1.getY() + 0.1F), (double) ((float) blockposition1.getZ() + 0.5F), 0.0F, 0.0F); - entityplayer1.setRespawnPosition(blockposition, flag1); - } else { - entityplayer1.playerConnection.sendPacket(new PacketPlayOutGameStateChange(0, 0.0F)); + // CraftBukkit start - fire PlayerRespawnEvent + if (location == null) { + boolean isBedSpawn = false; + CraftWorld cworld = (CraftWorld) this.server.server.getWorld(entityplayer.spawnWorld); + if (cworld != null && blockposition != null) { + blockposition1 = EntityHuman.getBed(cworld.getHandle(), blockposition, flag1); + if (blockposition1 != null) { + isBedSpawn = true; + location = new Location(cworld, (double) ((float) blockposition1.getX() + 0.5F), (double) ((float) blockposition1.getY() + 0.1F), (double) ((float) blockposition1.getZ() + 0.5F)); + } else { + entityplayer1.setRespawnPosition(null, true); + entityplayer1.playerConnection.sendPacket(new PacketPlayOutGameStateChange(0, 0.0F)); + } + } + + if (location == null) { + cworld = (CraftWorld) this.server.server.getWorlds().get(0); + blockposition = entityplayer1.getSpawnPoint(this.server, cworld.getHandle()); + location = new Location(cworld, (double) ((float) blockposition.getX() + 0.5F), (double) ((float) blockposition.getY() + 0.1F), (double) ((float) blockposition.getZ() + 0.5F)); } + + Player respawnPlayer = cserver.getPlayer(entityplayer1); + PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn); + cserver.getPluginManager().callEvent(respawnEvent); + + location = respawnEvent.getRespawnLocation(); + entityplayer.reset(); + } else { + location.setWorld(server.getWorldServer(i).getWorld()); } + WorldServer worldserver = ((CraftWorld) location.getWorld()).getHandle(); + entityplayer1.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + // CraftBukkit end worldserver.getChunkProviderServer().getChunkAt((int) entityplayer1.locX >> 4, (int) entityplayer1.locZ >> 4); - while (!worldserver.getCubes(entityplayer1, entityplayer1.getBoundingBox()).isEmpty() && entityplayer1.locY < 256.0D) { + while (avoidSuffocation && !worldserver.getCubes(entityplayer1, entityplayer1.getBoundingBox()).isEmpty() && entityplayer1.locY < 256.0D) { entityplayer1.setPosition(entityplayer1.locX, entityplayer1.locY + 1.0D, entityplayer1.locZ); } + // CraftBukkit start + byte actualDimension = (byte) (worldserver.getWorld().getEnvironment().getId()); + // Force the client to refresh their chunk cache + if (fromWorld.getEnvironment() == worldserver.getWorld().getEnvironment()) { + entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn((byte) (actualDimension >= 0 ? -1 : 0), worldserver.getDifficulty(), worldserver.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode())); + } - entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(entityplayer1.dimension, entityplayer1.world.getDifficulty(), entityplayer1.world.getWorldData().getType(), entityplayer1.playerInteractManager.getGameMode())); + entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(actualDimension, worldserver.getDifficulty(), worldserver.getWorldData().getType(), entityplayer1.playerInteractManager.getGameMode())); + entityplayer1.spawnIn(worldserver); + entityplayer1.dead = false; + entityplayer1.playerConnection.teleport(new Location(worldserver.getWorld(), entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch)); + entityplayer1.setSneaking(false); blockposition1 = worldserver.getSpawn(); - entityplayer1.playerConnection.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch); + // entityplayer1.playerConnection.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch); entityplayer1.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(blockposition1)); entityplayer1.playerConnection.sendPacket(new PacketPlayOutExperience(entityplayer1.exp, entityplayer1.expTotal, entityplayer1.expLevel)); this.b(entityplayer1, worldserver); this.f(entityplayer1); - worldserver.getPlayerChunkMap().addPlayer(entityplayer1); - worldserver.addEntity(entityplayer1); - this.players.add(entityplayer1); - this.j.put(entityplayer1.getUniqueID(), entityplayer1); - entityplayer1.syncInventory(); + if (!entityplayer.playerConnection.isDisconnected()) { + worldserver.getPlayerChunkMap().addPlayer(entityplayer1); + worldserver.addEntity(entityplayer1); + this.players.add(entityplayer1); + this.j.put(entityplayer1.getUniqueID(), entityplayer1); + } + // entityplayer1.syncInventory(); entityplayer1.setHealth(entityplayer1.getHealth()); + // Added from changeDimension + updateClient(entityplayer); // Update health, etc... + entityplayer.updateAbilities(); + for (Object o1 : entityplayer.getEffects()) { + MobEffect mobEffect = (MobEffect) o1; + entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect)); + } + + // Fire advancement trigger + CriterionTriggers.u.a(entityplayer, ((CraftWorld) fromWorld).getHandle().worldProvider.getDimensionManager(), worldserver.worldProvider.getDimensionManager()); + if (((CraftWorld) fromWorld).getHandle().worldProvider.getDimensionManager() == DimensionManager.NETHER && worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD && entityplayer.Q() != null) { + CriterionTriggers.B.a(entityplayer, entityplayer.Q()); + } + + // Don't fire on respawn + if (fromWorld != location.getWorld()) { + PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld); + server.server.getPluginManager().callEvent(event); + } + + // Save player file again if they were disconnected + if (entityplayer.playerConnection.isDisconnected()) { + this.savePlayerFile(entityplayer); + } + // CraftBukkit end return entityplayer1; } + // CraftBukkit start - Replaced the standard handling of portals with a more customised method. + public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) { + WorldServer exitWorld = null; + if (entityplayer.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds + // only target existing worlds (compensate for allow-nether/allow-end as false) + for (WorldServer world : this.server.worlds) { + if (world.dimension == i) { + exitWorld = world; + } + } + } + + Location enter = entityplayer.getBukkitEntity().getLocation(); + Location exit = null; + boolean useTravelAgent = false; // don't use agent for custom worlds or return from THE_END + if (exitWorld != null) { + if ((cause == TeleportCause.END_PORTAL) && (i == 0)) { + // THE_END -> NORMAL; use bed if available, otherwise default spawn + exit = ((org.bukkit.craftbukkit.entity.CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation(); + if (exit == null || ((CraftWorld) exit.getWorld()).getHandle().dimension != 0) { + exit = exitWorld.getWorld().getSpawnLocation(); + } + } else { + // NORMAL <-> NETHER or NORMAL -> THE_END + exit = this.calculateTarget(enter, exitWorld); + useTravelAgent = true; + } + } + + TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().getTravelAgent() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins + PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause); + event.useTravelAgent(useTravelAgent); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled() || event.getTo() == null) { + return; + } + + exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo(); + if (exit == null) { + return; + } + exitWorld = ((CraftWorld) exit.getWorld()).getHandle(); + + org.bukkit.event.player.PlayerTeleportEvent tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(entityplayer.getBukkitEntity(), enter, exit, cause); + Bukkit.getServer().getPluginManager().callEvent(tpEvent); + if (tpEvent.isCancelled() || tpEvent.getTo() == null) { + return; + } + + Vector velocity = entityplayer.getBukkitEntity().getVelocity(); + exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity); + + entityplayer.worldChangeInvuln = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds + this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we + if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) { + entityplayer.getBukkitEntity().setVelocity(velocity); + } + } + public void f(EntityPlayer entityplayer) { GameProfile gameprofile = entityplayer.getProfile(); int i = this.isOp(gameprofile) ? this.operators.a(gameprofile) : 0; @@ -498,12 +800,111 @@ } public void changeWorld(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) { + // CraftBukkit start - Split into modular functions + Location exit = calculateTarget(entity.getBukkitEntity().getLocation(), worldserver1); + repositionEntity(entity, exit, true); + } + + // Copy of original changeWorld(Entity, int, WorldServer, WorldServer) method with only location calculation logic + public Location calculateTarget(Location enter, World target) { + WorldServer worldserver = ((CraftWorld) enter.getWorld()).getHandle(); + WorldServer worldserver1 = ((CraftWorld) target.getWorld()).getHandle(); + int i = worldserver.dimension; + + double y = enter.getY(); + float yaw = enter.getYaw(); + float pitch = enter.getPitch(); + double d0 = enter.getX(); + double d1 = enter.getZ(); + double d2 = 8.0D; + /* double d0 = entity.locX; double d1 = entity.locZ; double d2 = 8.0D; float f = entity.yaw; + */ worldserver.methodProfiler.a("moving"); + if (worldserver1.dimension == -1) { + d0 = MathHelper.a(d0 / d2, worldserver1.getWorldBorder().b()+ 16.0D, worldserver1.getWorldBorder().d() - 16.0D); + d1 = MathHelper.a(d1 / d2, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D); + /* + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ + } else if (worldserver1.dimension == 0) { + d0 = MathHelper.a(d0 * d2, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D); + d1 = MathHelper.a(d1 * d2, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D); + /* + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ + } else { + BlockPosition blockposition; + + if (i == 1) { + // use default NORMAL world spawn instead of target + worldserver1 = this.server.worlds.get(0); + blockposition = worldserver1.getSpawn(); + } else { + blockposition = worldserver1.getDimensionSpawn(); + } + + d0 = (double) blockposition.getX(); + y = (double) blockposition.getY(); + d1 = (double) blockposition.getZ(); + /* + entity.setPositionRotation(d0, entity.locY, d1, 90.0F, 0.0F); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ + } + + worldserver.methodProfiler.b(); + if (i != 1) { + worldserver.methodProfiler.a("placing"); + d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872); + d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872); + /* + if (entity.isAlive()) { + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + worldserver1.getTravelAgent().a(entity, f); + worldserver1.addEntity(entity); + worldserver1.entityJoinedWorld(entity, false); + } + */ + + worldserver.methodProfiler.b(); + } + + // entity.spawnIn(worldserver1); + return new Location(worldserver1.getWorld(), d0, y, d1, yaw, pitch); + } + + // copy of original a(Entity, int, WorldServer, WorldServer) method with only entity repositioning logic + public void repositionEntity(Entity entity, Location exit, boolean portal) { + WorldServer worldserver = (WorldServer) entity.world; + WorldServer worldserver1 = ((CraftWorld) exit.getWorld()).getHandle(); + int i = worldserver.dimension; + + /* + double d0 = entity.locX; + double d1 = entity.locZ; + double d2 = 8.0D; + float f = entity.yaw; + */ + + worldserver.methodProfiler.a("moving"); + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + /* if (entity.dimension == -1) { d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D); d1 = MathHelper.a(d1 / 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D); @@ -522,6 +923,8 @@ BlockPosition blockposition; if (i == 1) { + // use default NORMAL world spawn instead of target + worldserver1 = this.server.worlds.get(0); blockposition = worldserver1.getSpawn(); } else { blockposition = worldserver1.getDimensionSpawn(); @@ -535,16 +938,27 @@ worldserver.entityJoinedWorld(entity, false); } } + */ worldserver.methodProfiler.b(); if (i != 1) { worldserver.methodProfiler.a("placing"); + /* d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872); d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872); + */ if (entity.isAlive()) { - entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); - worldserver1.getTravelAgent().a(entity, f); - worldserver1.addEntity(entity); + // entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + // worldserver1.getTravelAgent().a(entity, f); + if (portal) { + Vector velocity = entity.getBukkitEntity().getVelocity(); + worldserver1.getTravelAgent().adjustExit(entity, exit, velocity); + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); + if (entity.motX != velocity.getX() || entity.motY != velocity.getY() || entity.motZ != velocity.getZ()) { + entity.getBukkitEntity().setVelocity(velocity); + } + } + // worldserver1.addEntity(entity); worldserver1.entityJoinedWorld(entity, false); } @@ -552,11 +966,23 @@ } entity.spawnIn(worldserver1); + // CraftBukkit end } public void tick() { if (++this.v > 600) { - this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, this.players)); + // CraftBukkit start + for (int i = 0; i < this.players.size(); ++i) { + final EntityPlayer target = (EntityPlayer) this.players.get(i); + + target.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, Iterables.filter(this.players, new Predicate() { + @Override + public boolean apply(EntityPlayer input) { + return target.getBukkitEntity().canSee(input.getBukkitEntity()); + } + }))); + } + // CraftBukkit end this.v = 0; } @@ -569,6 +995,25 @@ } + // CraftBukkit start - add a world/entity limited version + public void sendAll(Packet packet, EntityHuman entityhuman) { + for (int i = 0; i < this.players.size(); ++i) { + EntityPlayer entityplayer = this.players.get(i); + if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { + continue; + } + ((EntityPlayer) this.players.get(i)).playerConnection.sendPacket(packet); + } + } + + public void sendAll(Packet packet, World world) { + for (int i = 0; i < world.players.size(); ++i) { + ((EntityPlayer) world.players.get(i)).playerConnection.sendPacket(packet); + } + + } + // CraftBukkit end + public void a(Packet packet, int i) { for (int j = 0; j < this.players.size(); ++j) { EntityPlayer entityplayer = (EntityPlayer) this.players.get(j); @@ -667,11 +1112,23 @@ this.operators.add(new OpListEntry(gameprofile, this.server.q(), this.operators.b(gameprofile))); this.b(this.a(gameprofile.getId()), i); + // CraftBukkit start + Player player = server.server.getPlayer(gameprofile.getId()); + if (player != null) { + player.recalculatePermissions(); + } + // CraftBukkit end } public void removeOp(GameProfile gameprofile) { this.operators.remove(gameprofile); this.b(this.a(gameprofile.getId()), 0); + // CraftBukkit start + Player player = server.server.getPlayer(gameprofile.getId()); + if (player != null) { + player.recalculatePermissions(); + } + // CraftBukkit end } private void b(EntityPlayer entityplayer, int i) { @@ -696,7 +1153,7 @@ } public boolean isOp(GameProfile gameprofile) { - return this.operators.d(gameprofile) || this.server.R() && this.server.worldServer[0].getWorldData().u() && this.server.Q().equalsIgnoreCase(gameprofile.getName()) || this.u; + return this.operators.d(gameprofile) || this.server.R() && this.server.worlds.get(0).getWorldData().u() && this.server.Q().equalsIgnoreCase(gameprofile.getName()) || this.u; // CraftBukkit } @Nullable @@ -720,6 +1177,12 @@ for (int j = 0; j < this.players.size(); ++j) { EntityPlayer entityplayer = (EntityPlayer) this.players.get(j); + // CraftBukkit start - Test if player receiving packet can see the source of the packet + if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { + continue; + } + // CraftBukkit end + if (entityplayer != entityhuman && entityplayer.dimension == i) { double d4 = d0 - entityplayer.locX; double d5 = d1 - entityplayer.locY; @@ -767,7 +1230,7 @@ public void reloadWhitelist() {} public void b(EntityPlayer entityplayer, WorldServer worldserver) { - WorldBorder worldborder = this.server.worldServer[0].getWorldBorder(); + WorldBorder worldborder = entityplayer.world.getWorldBorder(); // CraftBukkit entityplayer.playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE)); entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle"))); @@ -775,16 +1238,21 @@ entityplayer.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(blockposition)); if (worldserver.isRaining()) { - entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F)); - entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, worldserver.j(1.0F))); - entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, worldserver.h(1.0F))); + // CraftBukkit start - handle player weather + // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F)); + // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, worldserver.j(1.0F))); + // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, worldserver.h(1.0F))); + entityplayer.setPlayerWeather(org.bukkit.WeatherType.DOWNFALL, false); + entityplayer.updateWeather(-worldserver.o, worldserver.o, -worldserver.q, worldserver.q); + // CraftBukkit end } } public void updateClient(EntityPlayer entityplayer) { entityplayer.updateInventory(entityplayer.defaultContainer); - entityplayer.triggerHealthUpdate(); + // entityplayer.triggerHealthUpdate(); + entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange entityplayer.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(entityplayer.inventory.itemInHandIndex)); } @@ -797,7 +1265,7 @@ } public String[] getSeenPlayers() { - return this.server.worldServer[0].getDataManager().getPlayerFileData().getSeenPlayers(); + return this.server.worlds.get(0).getDataManager().getPlayerFileData().getSeenPlayers(); // CraftBukkit } public boolean getHasWhitelist() { @@ -846,26 +1314,39 @@ } public void u() { - for (int i = 0; i < this.players.size(); ++i) { - ((EntityPlayer) this.players.get(i)).playerConnection.disconnect(new ChatMessage("multiplayer.disconnect.server_shutdown", new Object[0])); + // CraftBukkit start - disconnect safely + for (EntityPlayer player : this.players) { + player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message } + // CraftBukkit end } + // CraftBukkit start + public void sendMessage(IChatBaseComponent[] iChatBaseComponents) { + for (IChatBaseComponent component : iChatBaseComponents) { + sendMessage(component, true); + } + } + // CraftBukkit end + public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { this.server.sendMessage(ichatbasecomponent); ChatMessageType chatmessagetype = flag ? ChatMessageType.SYSTEM : ChatMessageType.CHAT; - this.sendAll(new PacketPlayOutChat(ichatbasecomponent, chatmessagetype)); + // CraftBukkit start - we run this through our processor first so we can get web links etc + this.sendAll(new PacketPlayOutChat(CraftChatMessage.fixComponent(ichatbasecomponent), chatmessagetype)); + // CraftBukkit end } public void sendMessage(IChatBaseComponent ichatbasecomponent) { this.sendMessage(ichatbasecomponent, true); } - public ServerStatisticManager getStatisticManager(EntityHuman entityhuman) { + public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) { UUID uuid = entityhuman.getUniqueID(); - ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) this.o.get(uuid); + ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) entityhuman.getStatisticManager(); + // CraftBukkit end if (serverstatisticmanager == null) { File file = new File(this.server.getWorldServer(0).getDataManager().getDirectory(), "stats"); @@ -881,7 +1362,7 @@ serverstatisticmanager = new ServerStatisticManager(this.server, file1); serverstatisticmanager.a(); - this.o.put(uuid, serverstatisticmanager); + // this.o.put(uuid, serverstatisticmanager); // CraftBukkit } return serverstatisticmanager; @@ -889,14 +1370,14 @@ public AdvancementDataPlayer h(EntityPlayer entityplayer) { UUID uuid = entityplayer.getUniqueID(); - AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(uuid); + AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit if (advancementdataplayer == null) { File file = new File(this.server.getWorldServer(0).getDataManager().getDirectory(), "advancements"); File file1 = new File(file, uuid + ".json"); advancementdataplayer = new AdvancementDataPlayer(this.server, file1, entityplayer); - this.p.put(uuid, advancementdataplayer); + // this.p.put(uuid, advancementdataplayer); // CraftBukkit } advancementdataplayer.a(entityplayer); @@ -909,8 +1390,10 @@ WorldServer[] aworldserver = this.server.worldServer; int j = aworldserver.length; - for (int k = 0; k < j; ++k) { - WorldServer worldserver = aworldserver[k]; + // CraftBukkit start + for (int k = 0; k < server.worlds.size(); ++k) { + WorldServer worldserver = server.worlds.get(0); + // CraftBukkit end if (worldserver != null) { worldserver.getPlayerChunkMap().a(i); @@ -934,13 +1417,20 @@ } public void reload() { - Iterator iterator = this.p.values().iterator(); + // CraftBukkit start + /*Iterator iterator = this.p.values().iterator(); while (iterator.hasNext()) { AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next(); advancementdataplayer.b(); + }*/ + + for (EntityPlayer player : players) { + player.getAdvancementData().b(); + player.getAdvancementData().b(player); // CraftBukkit - trigger immediate flush of advancements } + // CraftBukkit end } }