Implement new API for ItemsAdder item deletion (#2353)

This commit is contained in:
tastybento 2024-05-11 08:49:47 -07:00 committed by GitHub
parent b8e1f33800
commit 4a0d44c035
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 59 additions and 9 deletions

View File

@ -372,7 +372,7 @@
<dependency>
<groupId>com.github.LoneDev6</groupId>
<artifactId>api-itemsadder</artifactId>
<version>3.6.1</version>
<version>3.6.3-beta-14</version>
<scope>provided</scope>
</dependency>
<!-- Multipaper -->

View File

@ -7,6 +7,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.io.Files;
import world.bentobox.bentobox.BentoBox;
/**
* Provides a shell for addons to become Plugins so that other Plugins
* can tap into their API more easily. Plugin + addon = Pladdon
@ -16,6 +18,8 @@ import com.google.common.io.Files;
public abstract class Pladdon extends JavaPlugin {
private static final String ADDONS_FOLDER = "BentoBox" + File.separator + "addons";
private static final String PAPER_REMAPPED = "plugins" + File.separator + ".paper-remapped" + File.separator
+ "unknown-origin";
/**
* This must return a new instance of the addon. It is called when the Pladdon is loaded.
@ -26,9 +30,10 @@ public abstract class Pladdon extends JavaPlugin {
@Override
public void onLoad() {
String parentFolder = getFile().getParent();
BentoBox.getInstance().logDebug("LOOK HERE: " + parentFolder);
if (parentFolder == null || !parentFolder.endsWith(ADDONS_FOLDER)) {
// Jar is in the wrong place. Let's move it
moveJar();
//moveJar();
}
}

View File

@ -1,6 +1,11 @@
package world.bentobox.bentobox.hooks;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
@ -8,6 +13,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.eclipse.jdt.annotation.Nullable;
import dev.lone.itemsadder.api.CustomBlock;
import world.bentobox.bentobox.BentoBox;
@ -22,6 +28,19 @@ import world.bentobox.bentobox.managers.RanksManager;
* Hook to enable itemsadder blocks to be deleted when islands are deleted.
* It also includes a flag to track explosion access
*/
/*
* add some methods under CustomBlock#Advanced class.
public static void deleteAllCustomBlocksInChunk(Chunk chunk)
@Nullable
public List<Location> getAllBlocksLocationsList(Chunk chunk)
@Nullable
public Map<String, Location> getAllBlocksLocations(Chunk chunk)
public void runActionOnBlocks(Chunk chunk, BiConsumer<String, Location> action)
*/
public class ItemsAdderHook extends Hook {
/**
@ -78,6 +97,24 @@ public class ItemsAdderHook extends Hook {
// CustomBlock.remove(location);
}
public static void deleteAllCustomBlocksInChunk(Chunk chunk) {
CustomBlock.Advanced.deleteAllCustomBlocksInChunk(chunk);
}
@Nullable
public List<Location> getAllBlocksLocationsList(Chunk chunk) {
return CustomBlock.Advanced.getAllBlocksLocationsList(chunk);
}
@Nullable
public Map<Location, String> getAllBlocksLocations(Chunk chunk) {
return CustomBlock.Advanced.getAllBlocksLocations(chunk);
}
public void runActionOnBlocks(Chunk chunk, BiConsumer<String, Location> action) {
CustomBlock.Advanced.runActionOnBlocks(chunk, action);
}
class BlockInteractListener extends FlagListener {
/**

View File

@ -8,6 +8,8 @@ import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
@ -33,11 +35,13 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.Colorable;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BoundingBox;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import io.papermc.lib.PaperLib;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.hooks.Hook;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.hooks.ItemsAdderHook;
import world.bentobox.bentobox.hooks.SlimefunHook;
@ -119,7 +123,8 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
return regenerateChunk(null, chunk.getWorld(), chunk.getX(), chunk.getZ());
}
private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, World world, int chunkX, int chunkZ) {
private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, @NonNull World world, int chunkX,
int chunkZ) {
CompletableFuture<Chunk> seedWorldFuture = getSeedWorldChunk(world, chunkX, chunkZ);
@ -201,10 +206,12 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
// Delete any 3rd party blocks
Location loc = new Location(toChunk.getWorld(), baseX + x, y, baseZ + z);
slimefunHook.ifPresent(hook -> hook.clearBlockInfo(loc, true));
itemsAdderHook.ifPresent(hook -> hook.clearBlockInfo(loc));
}
}
}
// Items Adder
itemsAdderHook.ifPresent(hook -> ItemsAdderHook.deleteAllCustomBlocksInChunk(toChunk));
// Entities
Arrays.stream(fromChunk.getEntities()).forEach(e -> processEntity(e, e.getLocation().toVector().toLocation(toChunk.getWorld())));
@ -333,7 +340,8 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
}
@SuppressWarnings("deprecation")
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) {
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, @Nonnull World world,
int chunkX, int chunkZ) {
CompletableFuture<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)
@ -370,6 +378,7 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
double baseZ = chunk.getZ() << 4;
int minHeight = chunk.getWorld().getMinHeight();
int maxHeight = chunk.getWorld().getMaxHeight();
Optional<Hook> slimefunHook = plugin.getHooks().getHook("Slimefun");
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
if (!limitBox.contains(baseX + x, 0, baseZ + z)) {
@ -383,12 +392,11 @@ public abstract class CopyWorldRegenerator implements WorldRegenerator {
}
// Delete any 3rd party blocks
Location loc = new Location(chunk.getWorld(), baseX + x, y, baseZ + z);
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
plugin.getHooks().getHook("ItemsAdder")
.ifPresent(hook -> ((ItemsAdderHook) hook).clearBlockInfo(loc));
slimefunHook.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
}
}
}
// Items Adder
plugin.getHooks().getHook("ItemsAdder").ifPresent(hook -> ItemsAdderHook.deleteAllCustomBlocksInChunk(chunk));
}
}