2020-04-22 00:06:30 +02:00
From bb23022f8a18e30fb96036e8c6c7517af3ae42d6 Mon Sep 17 00:00:00 2001
2020-04-19 10:32:04 +02:00
From: Aikar <aikar@aikar.co>
Date: Sun, 19 Apr 2020 04:28:29 -0400
Subject: [PATCH] Load Chunks for Login Asynchronously
2020-04-22 08:52:17 +02:00
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 96a47dd1c2..96ebe0b226 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1382,7 +1382,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.pitch = MathHelper.a(f1, -90.0F, 90.0F) % 360.0F;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
- world.getChunkAt((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4); // CraftBukkit
+ if (valid) world.getChunkAt((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4); // CraftBukkit // Paper
}
public void setPositionRotation(BlockPosition blockposition, float f, float f1) {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 7929fcc800..c3710b73af 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -142,6 +142,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
// CraftBukkit end
public void tick() {
+ if (!this.player.valid) return; // Paper
this.syncPosition();
this.player.lastX = this.player.locX();
this.player.lastY = this.player.locY();
2020-04-19 10:32:04 +02:00
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2020-04-22 08:52:17 +02:00
index ec45c30dd3..de55423686 100644
2020-04-19 10:32:04 +02:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2020-04-22 08:52:17 +02:00
@@ -173,6 +173,17 @@ public abstract class PlayerList {
this.players.add(entityplayer);
this.playersByName.put(entityplayer.getName().toLowerCase(java.util.Locale.ROOT), entityplayer); // Spigot
this.j.put(entityplayer.getUniqueID(), entityplayer);
2020-04-19 10:32:04 +02:00
+ // Paper start - async load spawn in chunk
+ WorldServer finalWorldserver = worldserver;
2020-04-19 19:58:02 +02:00
+ worldserver.getChunkProvider().getTickingChunkAsync(loc.getBlockX() >> 4, loc.getBlockZ() >> 4, (chunk -> { // use ticking - as it has at least 1 neighbours loaded
2020-04-22 08:52:17 +02:00
+ postChunkLoadJoin(entityplayer, finalWorldserver, playerconnection, nbttagcompound, networkmanager.getSocketAddress().toString(), joinMessage);
2020-04-19 10:32:04 +02:00
+ }));
+ }
2020-04-22 08:52:17 +02:00
+ private void postChunkLoadJoin(EntityPlayer entityplayer, WorldServer worldserver, PlayerConnection playerconnection, NBTTagCompound nbttagcompound, String s1, String joinMessage) {
+ if (!entityplayer.playerConnection.networkManager.isConnected()) {
+ return;
+ }
2020-04-19 10:32:04 +02:00
+ // Paper end
2020-04-22 08:52:17 +02:00
// this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{entityplayer})); // CraftBukkit - replaced with loop below
// Paper start - correctly register player BEFORE PlayerJoinEvent, so the entity is valid and doesn't require tick delay hacks
2020-04-19 10:32:04 +02:00
--
2020-04-22 08:52:17 +02:00
2.25.1
2020-04-19 10:32:04 +02:00