From 56cf49c167b23f8693618475cc6330febab86a42 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 11 Dec 2020 15:36:42 +0000 Subject: [PATCH] Send chunks if they're in the paper no-tick-distance Fixes #766 and #677 --- worldedit-bukkit/build.gradle.kts | 6 +++ .../mc1_16_2/BukkitAdapter_1_16_2.java | 42 +++++++++++++++---- .../mc1_16_4/BukkitAdapter_1_16_4.java | 42 +++++++++++++++---- .../adapter/impl/regen/Regen_v1_15_R2.java | 4 ++ .../adapter/impl/regen/Regen_v1_16_R1.java | 4 ++ .../adapter/impl/regen/Regen_v1_16_R2.java | 4 ++ .../adapter/impl/regen/Regen_v1_16_R3.java | 4 ++ 7 files changed, 92 insertions(+), 14 deletions(-) diff --git a/worldedit-bukkit/build.gradle.kts b/worldedit-bukkit/build.gradle.kts index 6bba93ae2..eb767c152 100644 --- a/worldedit-bukkit/build.gradle.kts +++ b/worldedit-bukkit/build.gradle.kts @@ -39,9 +39,15 @@ dependencies { "api"(project(":worldedit-core")) "api"(project(":worldedit-libs:bukkit")) "compile"(":worldedit-adapters:") + // Paper-patched NMS jars + "compile"("com.destroystokyo.paperv1_15_r1:paperv1_15_r1:1_15_r1") + "compile"("com.destroystokyo.paperv1_16_r1:paperv1_16_r1:1_16_r1") + "compile"("com.destroystokyo.paperv1_16_r2:paperv1_16_r2:1_16_r2") + "compile"("com.destroystokyo.paperv1_16_r3:paperv1_16_r3:1_16_r3") "compile"("org.spigotmcv1_15_r1:spigotmcv1_15_r1:1_15_r1") "compile"("org.spigotmcv1_16_r1:spigotmcv1_16_r1:1_16_r1") "compile"("org.spigotmcv1_16_r2:spigotmcv1_16_r2:1_16_r2") + "compile"("org.spigotmcv1_16_r3:spigotmcv1_16_r3:1_16_r3") "implementation"("it.unimi.dsi:fastutil:${Versions.FAST_UTIL}") "api"("com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT") { exclude("junit", "junit") diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java index d0c5fb2cd..f75477317 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_2/BukkitAdapter_1_16_2.java @@ -9,6 +9,7 @@ import com.boydti.fawe.object.collection.BitArrayUnstretched; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; +import com.destroystokyo.paper.util.misc.PooledLinkedHashSets; import com.mojang.datafixers.util.Either; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; @@ -25,6 +26,7 @@ import net.minecraft.server.v1_16_R2.DataBits; import net.minecraft.server.v1_16_R2.DataPalette; import net.minecraft.server.v1_16_R2.DataPaletteBlock; import net.minecraft.server.v1_16_R2.DataPaletteLinear; +import net.minecraft.server.v1_16_R2.EntityPlayer; import net.minecraft.server.v1_16_R2.GameProfileSerializer; import net.minecraft.server.v1_16_R2.IBlockData; import net.minecraft.server.v1_16_R2.PacketPlayOutLightUpdate; @@ -205,14 +207,40 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter { playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { p.playerConnection.sendPacket(chunkpacket); }); - } - if (lighting) { - boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) - PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges); - playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { - p.playerConnection.sendPacket(packet); - }); + if (lighting) { + boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) + 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 null; + } + 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) { + boolean trustEdges = + true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) + PacketPlayOutLightUpdate packet = + new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges); + p.playerConnection.sendPacket(packet); + } + } + } } return null; }); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitAdapter_1_16_4.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitAdapter_1_16_4.java index d9f89cf2c..6e0ca22a1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitAdapter_1_16_4.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_4/BukkitAdapter_1_16_4.java @@ -9,6 +9,7 @@ import com.boydti.fawe.object.collection.BitArrayUnstretched; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; +import com.destroystokyo.paper.util.misc.PooledLinkedHashSets; import com.mojang.datafixers.util.Either; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; @@ -25,6 +26,7 @@ import net.minecraft.server.v1_16_R3.DataBits; import net.minecraft.server.v1_16_R3.DataPalette; import net.minecraft.server.v1_16_R3.DataPaletteBlock; import net.minecraft.server.v1_16_R3.DataPaletteLinear; +import net.minecraft.server.v1_16_R3.EntityPlayer; import net.minecraft.server.v1_16_R3.GameProfileSerializer; import net.minecraft.server.v1_16_R3.IBlockData; import net.minecraft.server.v1_16_R3.PacketPlayOutLightUpdate; @@ -205,14 +207,40 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter { playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { p.playerConnection.sendPacket(chunkpacket); }); - } - if (lighting) { - boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) - PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges); - playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> { - p.playerConnection.sendPacket(packet); - }); + if (lighting) { + boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) + 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 null; + } + 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) { + boolean trustEdges = + true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad) + PacketPlayOutLightUpdate packet = + new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges); + p.playerConnection.sendPacket(packet); + } + } + } } return null; }); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/regen/Regen_v1_15_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/regen/Regen_v1_15_R2.java index 937fc5de8..14edd27a8 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/regen/Regen_v1_15_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/regen/Regen_v1_15_R2.java @@ -505,5 +505,9 @@ public class Regen_v1_15_R2 extends Regenerator