From b7c7883f17d20f2a49bd8ad3df68d2ac96989c55 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 08:36:44 +0900 Subject: [PATCH 1/6] Delete slimefun chunks/blocks when island is deleted. --- pom.xml | 7 +++ .../world/bentobox/bentobox/BentoBox.java | 4 ++ .../bentobox/bentobox/hooks/SlimefunHook.java | 50 +++++++++++++++++++ .../bentobox/nms/CopyWorldRegenerator.java | 10 ++++ .../bentobox/nms/SimpleWorldRegenerator.java | 5 ++ 5 files changed, 76 insertions(+) create mode 100644 src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java diff --git a/pom.xml b/pom.xml index 68a3e2338..fc91f8455 100644 --- a/pom.xml +++ b/pom.xml @@ -314,6 +314,13 @@ ${spigot.version} provided + + + com.github.Slimefun + Slimefun4 + RC-36 + provided + diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index 60cbc2fe8..1fb0ed916 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -24,6 +24,7 @@ import world.bentobox.bentobox.database.DatabaseSetup; import world.bentobox.bentobox.hooks.MultiverseCoreHook; import world.bentobox.bentobox.hooks.MyWorldsHook; +import world.bentobox.bentobox.hooks.SlimefunHook; import world.bentobox.bentobox.hooks.VaultHook; import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook; import world.bentobox.bentobox.listeners.BannedCommands; @@ -231,6 +232,9 @@ private void completeSetup(long loadTime) { hooksManager.registerHook(new MyWorldsHook()); islandWorldManager.registerWorldsToMultiverse(true); + // Register Slimefun + hooksManager.registerHook(new SlimefunHook()); + // TODO: re-enable after implementation //hooksManager.registerHook(new DynmapHook()); // TODO: re-enable after rework diff --git a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java new file mode 100644 index 000000000..8ec2f3ec3 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java @@ -0,0 +1,50 @@ +/** + * + */ +package world.bentobox.bentobox.hooks; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; + +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import world.bentobox.bentobox.api.hooks.Hook; + +/** + * Hook to enable slimefun blocks to be deleted when islands are deleted. + */ +public class SlimefunHook extends Hook { + + private Slimefun sfPlugin; + + public SlimefunHook() { + super("SlimeFun", Material.SLIME_BLOCK); + } + + @Override + public boolean hook() { + // See if Slimefun is around + sfPlugin = (Slimefun) Bukkit.getPluginManager().getPlugin("SlimeFun"); + return sfPlugin != null; + } + + @Override + public String getFailureCause() { + return ""; // No errors + } + + public void clearAllBlockInfoAtChunk(World world, int x, int z, boolean destroy) { + if (!BlockStorage.isWorldLoaded(world)) { + return; // Not sure if this is needed. + } + BlockStorage.clearAllBlockInfoAtChunk(world, x, z, destroy); + } + + public void clearBlockInfo(Block b, boolean destroy) { + BlockStorage.clearBlockInfo(b, destroy); + } + + +} diff --git a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java index e8c60c53d..1158d6050 100644 --- a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java @@ -38,6 +38,7 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.database.objects.IslandDeletion; +import world.bentobox.bentobox.hooks.SlimefunHook; import world.bentobox.bentobox.util.MyBiomeGrid; /** @@ -117,6 +118,11 @@ 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 @@ -324,6 +330,10 @@ 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) diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index f37efc192..ee401bd45 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -21,6 +21,7 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.database.objects.IslandDeletion; +import world.bentobox.bentobox.hooks.SlimefunHook; import world.bentobox.bentobox.util.MyBiomeGrid; public abstract class SimpleWorldRegenerator implements WorldRegenerator { @@ -90,6 +91,10 @@ 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) From 513851d796b2a0ec8707b36dfc8bc1ae4f32a7fb Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 09:17:45 +0900 Subject: [PATCH 2/6] 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)); } } } From c8ab06db56e90fc00dabe06653cd1c382a53657e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 13:09:37 +0900 Subject: [PATCH 3/6] Fixed bugs and tested. --- src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java | 2 +- .../world/bentobox/bentobox/nms/CopyWorldRegenerator.java | 4 ++++ .../world/bentobox/bentobox/nms/SimpleWorldRegenerator.java | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java index ab0fdae98..0c1f9d1e7 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java @@ -21,7 +21,7 @@ public class SlimefunHook extends Hook { private Slimefun sfPlugin; public SlimefunHook() { - super("SlimeFun", Material.SLIME_BLOCK); + super("Slimefun", Material.SLIME_BLOCK); } @Override diff --git a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java index 946d6a0be..47b3821f3 100644 --- a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java @@ -381,6 +381,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)); } } } diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index 6a0cc2747..218c72af7 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -144,6 +144,7 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat } // Delete any slimefun blocks Location loc = new Location(chunk.getWorld(), baseX + x, y, baseZ + z); + BentoBox.getInstance().logDebug(loc + " " + plugin.getHooks().getHook("Slimefun").isPresent()); plugin.getHooks().getHook("Slimefun") .ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true)); } From b5ffcee86411ab20347ce7f5fb1cfb51c0ad8160 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 13:10:06 +0900 Subject: [PATCH 4/6] Remove unused comment --- src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java index 0c1f9d1e7..a3fe5b9a1 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.bentobox.hooks; import org.bukkit.Bukkit; From f4868f7953c3b33358195daffec5887696079937 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 13:13:50 +0900 Subject: [PATCH 5/6] Remove the chunk deletion for Slimefun. --- .../world/bentobox/bentobox/nms/CopyWorldRegenerator.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java index 47b3821f3..6b6a2800c 100644 --- a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java @@ -330,10 +330,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) From 9f116e75c4c2f05f012932004cb60b46d08a0214 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 24 Dec 2023 13:17:16 +0900 Subject: [PATCH 6/6] Simplify hook --- .../bentobox/bentobox/hooks/SlimefunHook.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java index a3fe5b9a1..897a247ca 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java @@ -3,10 +3,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import me.mrCookieSlime.Slimefun.api.BlockStorage; import world.bentobox.bentobox.api.hooks.Hook; @@ -15,8 +12,6 @@ */ public class SlimefunHook extends Hook { - private Slimefun sfPlugin; - public SlimefunHook() { super("Slimefun", Material.SLIME_BLOCK); } @@ -24,8 +19,7 @@ public SlimefunHook() { @Override public boolean hook() { // See if Slimefun is around - sfPlugin = (Slimefun) Bukkit.getPluginManager().getPlugin("SlimeFun"); - return sfPlugin != null; + return Bukkit.getPluginManager().getPlugin("SlimeFun") != null; } @Override @@ -33,17 +27,6 @@ public String getFailureCause() { return ""; // No errors } - public void clearAllBlockInfoAtChunk(World world, int x, int z, boolean destroy) { - if (!BlockStorage.isWorldLoaded(world)) { - return; // Not sure if this is needed. - } - BlockStorage.clearAllBlockInfoAtChunk(world, x, z, destroy); - } - - public void clearBlockInfo(Block b, boolean destroy) { - BlockStorage.clearBlockInfo(b, destroy); - } - public void clearBlockInfo(Location location, boolean destroy) { BlockStorage.clearBlockInfo(location, destroy); }