Skip to content

Commit

Permalink
Delete slimefun chunks/blocks when island is deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Dec 23, 2023
1 parent b260cf1 commit b7c7883
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java
Original file line number Diff line number Diff line change
@@ -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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -117,6 +118,11 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {
}

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
Expand Down Expand Up @@ -324,6 +330,10 @@ private boolean isEnded(int chunkX) {

@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -90,6 +91,10 @@ private boolean isEnded(int chunkX) {

@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)
Expand Down

0 comments on commit b7c7883

Please sign in to comment.