Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new API for ItemsAdder item deletion #2353

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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
Expand All @@ -16,6 +18,8 @@
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.
Expand All @@ -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();
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/world/bentobox/bentobox/hooks/ItemsAdderHook.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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;
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;
Expand All @@ -22,6 +28,19 @@
* 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 {

/**
Expand Down Expand Up @@ -78,6 +97,24 @@ public void clearBlockInfo(Location location) {
// 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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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;
Expand All @@ -33,11 +35,13 @@
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;
Expand Down Expand Up @@ -119,7 +123,8 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {
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);

Expand Down Expand Up @@ -201,10 +206,12 @@ private void copyChunkDataToChunk(Chunk toChunk, Chunk fromChunk, BoundingBox li
// 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())));

Expand Down Expand Up @@ -333,7 +340,8 @@ private boolean isEnded(int chunkX) {
}

@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)
Expand Down Expand Up @@ -370,6 +378,7 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat
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)) {
Expand All @@ -383,12 +392,11 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat
}
// 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));
}
}