Delete slimefun chunks/blocks when island is deleted.

This commit is contained in:
tastybento 2023-12-24 08:36:44 +09:00
parent b260cf1f4f
commit b7c7883f17
5 changed files with 76 additions and 0 deletions

View File

@ -314,6 +314,13 @@
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<!-- Slimefun -->
<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-36</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -24,6 +24,7 @@ import world.bentobox.bentobox.commands.BentoBoxCommand;
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 @@ public class BentoBox extends JavaPlugin implements Listener {
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

View File

@ -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);
}
}

View File

@ -38,6 +38,7 @@ import io.papermc.lib.PaperLib;
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 abstract class CopyWorldRegenerator implements WorldRegenerator {
}
private CompletableFuture<Void> 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<Chunk> 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 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
@SuppressWarnings("deprecation")
private CompletableFuture<Void> 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<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)

View File

@ -21,6 +21,7 @@ import io.papermc.lib.PaperLib;
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 @@ public abstract class SimpleWorldRegenerator implements WorldRegenerator {
@SuppressWarnings("deprecation")
private CompletableFuture<Void> 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<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)