From ae31d8312f9fde23b84f228963d6531f10e9dc53 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 12 Apr 2021 00:23:42 +0200 Subject: [PATCH] Simplify and clean up sendChunk Hopefully, that doesn't cause any issues --- .../mc1_16_5/BukkitAdapter_1_16_5.java | 65 ++++++------------- 1 file changed, 19 insertions(+), 46 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BukkitAdapter_1_16_5.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BukkitAdapter_1_16_5.java index b044166a3..c34cb0f4c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BukkitAdapter_1_16_5.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_5/BukkitAdapter_1_16_5.java @@ -198,53 +198,26 @@ public final class BukkitAdapter_1_16_5 extends NMSAdapter { if (playerChunk == null) { return; } - if (playerChunk.hasBeenLoaded()) { - ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ); - Optional optional = ((Either) playerChunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left(); - if (optional.isPresent()) { - PacketPlayOutMapChunk chunkpacket = new PacketPlayOutMapChunk(optional.get(), 65535); - playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { - p.playerConnection.sendPacket(chunkpacket); - }); - - if (lighting) { - //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) - boolean trustEdges = true; - PacketPlayOutLightUpdate packet = - new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), + ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ); + Optional optional = ((Either) playerChunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left(); + Chunk chunk = optional.orElseGet(() -> + nmsWorld.getChunkProvider().getChunkAtIfLoadedImmediately(chunkX, chunkZ)); + if (chunk == null) { + return; + } + PacketPlayOutMapChunk chunkPacket = new PacketPlayOutMapChunk(chunk, 65535); + playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { + p.playerConnection.sendPacket(chunkPacket); + }); + if (lighting) { + //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) + boolean trustEdges = true; + PacketPlayOutLightUpdate packet = + new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges); - playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { - p.playerConnection.sendPacket(packet); - }); - } - } else if (PaperLib.isPaper()) { - //Require generic here to work with multiple dependencies trying to take control. - PooledLinkedHashSets.PooledObjectLinkedOpenHashSet objects = - nmsWorld.getChunkProvider().playerChunkMap.playerViewDistanceNoTickMap - .getObjectsInRange(chunkX, chunkZ); - if (objects == null) { - return; - } - for (Object obj : objects.getBackingSet()) { - if (obj == null) { - continue; - } - EntityPlayer p = (EntityPlayer) obj; - Chunk chunk = nmsWorld.getChunkProvider().getChunkAtIfLoadedImmediately(chunkX, chunkZ); - if (chunk != null) { - PacketPlayOutMapChunk chunkpacket = new PacketPlayOutMapChunk(chunk, 65535); - p.playerConnection.sendPacket(chunkpacket); - - if (lighting) { - //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) - boolean trustEdges = true; - PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, - nmsWorld.getChunkProvider().getLightEngine(), trustEdges); - p.playerConnection.sendPacket(packet); - } - } - } - } + playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { + p.playerConnection.sendPacket(packet); + }); } }