From 6a0582a9506d8d35679ce3c1323d0dc4b1c07724 Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 9 Mar 2021 07:08:35 +0100 Subject: [PATCH] Do not send all chunks on logging, wait for the settings packet instead --- .../net/minestom/server/entity/Player.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 385646ad8..c0e9188a1 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -709,10 +709,7 @@ public class Player extends LivingEntity implements CommandSender { teleport(spawnPosition); } else if (updateChunks) { // Send newly visible chunks to player once spawned in the instance - final Chunk chunk = getChunk(); - if (chunk != null) { - refreshVisibleChunks(chunk); - } + refreshVisibleChunks(); } if (dimensionChange || firstSpawn) { @@ -1549,6 +1546,13 @@ public class Player extends LivingEntity implements CommandSender { } } + public void refreshVisibleChunks() { + final Chunk chunk = getChunk(); + if (chunk != null) { + refreshVisibleChunks(chunk); + } + } + /** * Refreshes the list of entities that the player should be able to see based on {@link MinecraftServer#getEntityViewDistance()} * and {@link Entity#isAutoViewable()}. @@ -2325,7 +2329,11 @@ public class Player extends LivingEntity implements CommandSender { final int serverRange = MinecraftServer.getChunkViewDistance(); final int playerRange = getSettings().viewDistance; if (playerRange == 0) { - return serverRange; // Didn't receive settings packet yet (is the case on login) + // Didn't receive settings packet yet (is the case on login) + // In this case we send the smallest amount of chunks possible + // Will be updated in PlayerSettings#refresh. + // Non-compliant clients might also be stuck with this view + return 1; } else { return Math.min(playerRange, serverRange); } @@ -2585,7 +2593,7 @@ public class Player extends LivingEntity implements CommandSender { public void refresh(String locale, byte viewDistance, ChatMode chatMode, boolean chatColors, byte displayedSkinParts, MainHand mainHand) { - final boolean viewDistanceChanged = !firstRefresh && this.viewDistance != viewDistance; + final boolean viewDistanceChanged = this.viewDistance != viewDistance; this.locale = locale; this.viewDistance = viewDistance; @@ -2600,10 +2608,7 @@ public class Player extends LivingEntity implements CommandSender { // Client changed his view distance in the settings if (viewDistanceChanged) { - final Chunk playerChunk = getChunk(); - if (playerChunk != null) { - refreshVisibleChunks(playerChunk); - } + refreshVisibleChunks(); } }