From 513851d796b2a0ec8707b36dfc8bc1ae4f32a7fb Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 09:17:45 +0900 Subject: [PATCH] Switch from chunk to block notification. Individual blocks need to be destroyed because complete chunks may not be used. --- .../java/world/bentobox/bentobox/hooks/SlimefunHook.java | 5 +++++ .../bentobox/bentobox/nms/CopyWorldRegenerator.java | 8 ++++---- .../bentobox/bentobox/nms/SimpleWorldRegenerator.java | 9 +++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java index 8ec2f3ec3..ab0fdae98 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java @@ -4,6 +4,7 @@ package world.bentobox.bentobox.hooks; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -46,5 +47,9 @@ public void clearBlockInfo(Block b, boolean destroy) { BlockStorage.clearBlockInfo(b, destroy); } + public void clearBlockInfo(Location location, boolean destroy) { + BlockStorage.clearBlockInfo(location, destroy); + } + } diff --git a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java index 1158d6050..946d6a0be 100644 --- a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java @@ -119,10 +119,6 @@ public CompletableFuture regenerateChunk(Chunk chunk) { private CompletableFuture regenerateChunk(@Nullable IslandDeletion di, World world, int chunkX, int chunkZ) { - // Notify Slimefun - plugin.getHooks().getHook("Slimefun") - .ifPresent(sf -> ((SlimefunHook) sf).clearAllBlockInfoAtChunk(world, chunkX, chunkZ, true)); - CompletableFuture seedWorldFuture = getSeedWorldChunk(world, chunkX, chunkZ); // Set up a future to get the chunk requests using Paper's Lib. If Paper is used, this should be done async @@ -198,6 +194,10 @@ private void copyChunkDataToChunk(Chunk toChunk, Chunk fromChunk, BoundingBox li if (x % 4 == 0 && y % 4 == 0 && z % 4 == 0) { toChunk.getBlock(x, y, z).setBiome(fromChunk.getBlock(x, y, z).getBiome()); } + // Delete any slimefun blocks + Location loc = new Location(toChunk.getWorld(), baseX + x, y, baseZ + z); + plugin.getHooks().getHook("Slimefun") + .ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true)); } } } diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index ee401bd45..6a0cc2747 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -7,6 +7,7 @@ import java.util.concurrent.CompletableFuture; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; @@ -91,10 +92,6 @@ private boolean isEnded(int chunkX) { @SuppressWarnings("deprecation") private CompletableFuture regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) { - // Notify Slimefun - plugin.getHooks().getHook("Slimefun") - .ifPresent(sf -> ((SlimefunHook) sf).clearAllBlockInfoAtChunk(world, chunkX, chunkZ, true)); - CompletableFuture chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ); CompletableFuture invFuture = chunkFuture.thenAccept(chunk -> Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance) @@ -145,6 +142,10 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat if (x % 4 == 0 && y % 4 == 0 && z % 4 == 0) { chunk.getBlock(x, y, z).setBiome(biomeGrid.getBiome(x, y, z)); } + // Delete any slimefun blocks + Location loc = new Location(chunk.getWorld(), baseX + x, y, baseZ + z); + plugin.getHooks().getHook("Slimefun") + .ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true)); } } }