From 54f762e2f727a23d42c06a646d9a07a124ea65e9 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 19 Apr 2020 04:32:04 -0400 Subject: [PATCH] Load Chunks for Login Asynchronously No longer will trigger Synchronous Chunk Loads when a player logs in to the server. Will delay PlayerJoinEvent until the chunk has been loaded. Should have massive performance benefits for larger servers with lots of players logging in and out. --- ...Load-Chunks-for-Login-Asynchronously.patch | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Spigot-Server-Patches/0487-Load-Chunks-for-Login-Asynchronously.patch diff --git a/Spigot-Server-Patches/0487-Load-Chunks-for-Login-Asynchronously.patch b/Spigot-Server-Patches/0487-Load-Chunks-for-Login-Asynchronously.patch new file mode 100644 index 0000000000..c6fbae1adc --- /dev/null +++ b/Spigot-Server-Patches/0487-Load-Chunks-for-Login-Asynchronously.patch @@ -0,0 +1,41 @@ +From 5bfa76db63cb31d5187548eea7b1cc94f3ab2c3e Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sun, 19 Apr 2020 04:28:29 -0400 +Subject: [PATCH] Load Chunks for Login Asynchronously + + +diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java +index e737381b3..83ceb3f99 100644 +--- a/src/main/java/net/minecraft/server/PlayerList.java ++++ b/src/main/java/net/minecraft/server/PlayerList.java +@@ -106,8 +106,9 @@ public abstract class PlayerList { + // 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; ++ s = bukkit.hasKeyOfType("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s; // Diff below + } ++ String lastKnownName = s; // Paper + if (nbttagcompound == null) entityplayer.moveToSpawn(worldserver); // Paper - only move to spawn on first login, otherwise, stay where you are.... + // CraftBukkit end + +@@ -132,6 +133,16 @@ public abstract class PlayerList { + entityplayer.setYawPitch(loc.getYaw(), loc.getPitch()); + // Spigot end + ++ // Paper start - async load spawn in chunk ++ WorldServer finalWorldserver = worldserver; ++ worldserver.getChunkProvider().getChunkAtAsynchronously(loc.getBlockX() >> 4, loc.getBlockZ() >> 4, true, (chunk -> { ++ if (networkmanager.isConnected()) { ++ postChunkLoadJoin(entityplayer, finalWorldserver, nbttagcompound, networkmanager, lastKnownName, networkmanager.getSocketAddress().toString()); ++ } ++ })); ++ } ++ private void postChunkLoadJoin(EntityPlayer entityplayer, WorldServer worldserver, NBTTagCompound nbttagcompound, NetworkManager networkmanager, String s, String s1) { ++ // Paper end + // CraftBukkit - Moved message to after join + // PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ()); + WorldData worlddata = worldserver.getWorldData(); +-- +2.25.1 +