diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index d81436643..2b46d201b 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -546,21 +546,27 @@ public class Player extends LivingEntity implements CommandSender, Localizable, if (!firstSpawn) { // Player instance changed, clear current viewable collections previousChunks.forEach(chunk -> chunk.removeViewer(this)); + + //TODO: entity#removeViewer sends a packet for each removed entity + //Sending destroy entity packets is not necessary when the dimension changes + //and, potentially, this could also be rewritten to send only a single DestroyEntitiesPacket + //with the list of all destroyed entities this.viewableEntities.forEach(entity -> entity.removeViewer(this)); } - super.setInstance(instance, spawnPosition); - if (dimensionChange) { sendDimension(instance.getDimensionType()); } + super.setInstance(instance, spawnPosition); + if (updateChunks) { refreshVisibleChunks(); } + synchronizePosition(true); // So the player doesn't get stuck + if (dimensionChange || firstSpawn) { - synchronizePosition(true); // So the player doesn't get stuck this.inventory.update(); } diff --git a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java index 3b4c5a833..ee1ae34f2 100644 --- a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java +++ b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java @@ -134,6 +134,7 @@ public class FakePlayer extends Player implements NavigableEntity { protected boolean addViewer0(@NotNull Player player) { final boolean result = super.addViewer0(player); if (result) { + player.getPlayerConnection().sendPacket(getAddPlayerToList()); handleTabList(player.getPlayerConnection()); } return result;