Skip to content

Commit

Permalink
Delete slimefun chunks/blocks when island is deleted. (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento authored Dec 24, 2023
1 parent 96499f3 commit 86d8d14
Show file tree
Hide file tree
Showing 5 changed files with 63 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
35 changes: 35 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,35 @@
package world.bentobox.bentobox.hooks;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;

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 {

public SlimefunHook() {
super("Slimefun", Material.SLIME_BLOCK);
}

@Override
public boolean hook() {
// See if Slimefun is around
return Bukkit.getPluginManager().getPlugin("SlimeFun") != null;
}

@Override
public String getFailureCause() {
return ""; // No errors
}

public void clearBlockInfo(Location location, boolean destroy) {
BlockStorage.clearBlockInfo(location, 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,7 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {
}

private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, World world, int chunkX, int chunkZ) {

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 @@ -192,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));
}
}
}
Expand Down Expand Up @@ -371,6 +377,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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,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 @@ -140,6 +142,11 @@ 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);
BentoBox.getInstance().logDebug(loc + " " + plugin.getHooks().getHook("Slimefun").isPresent());
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
}
}
}
Expand Down

0 comments on commit 86d8d14

Please sign in to comment.