Skip to content

Commit 4a0d44c

Browse files
authored
Implement new API for ItemsAdder item deletion (#2353)
1 parent b8e1f33 commit 4a0d44c

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
<dependency>
373373
<groupId>com.github.LoneDev6</groupId>
374374
<artifactId>api-itemsadder</artifactId>
375-
<version>3.6.1</version>
375+
<version>3.6.3-beta-14</version>
376376
<scope>provided</scope>
377377
</dependency>
378378
<!-- Multipaper -->

src/main/java/world/bentobox/bentobox/api/addons/Pladdon.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import com.google.common.io.Files;
99

10+
import world.bentobox.bentobox.BentoBox;
11+
1012
/**
1113
* Provides a shell for addons to become Plugins so that other Plugins
1214
* can tap into their API more easily. Plugin + addon = Pladdon
@@ -16,6 +18,8 @@
1618
public abstract class Pladdon extends JavaPlugin {
1719

1820
private static final String ADDONS_FOLDER = "BentoBox" + File.separator + "addons";
21+
private static final String PAPER_REMAPPED = "plugins" + File.separator + ".paper-remapped" + File.separator
22+
+ "unknown-origin";
1923

2024
/**
2125
* 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 {
2630
@Override
2731
public void onLoad() {
2832
String parentFolder = getFile().getParent();
33+
BentoBox.getInstance().logDebug("LOOK HERE: " + parentFolder);
2934
if (parentFolder == null || !parentFolder.endsWith(ADDONS_FOLDER)) {
3035
// Jar is in the wrong place. Let's move it
31-
moveJar();
36+
//moveJar();
3237
}
3338
}
3439

src/main/java/world/bentobox/bentobox/hooks/ItemsAdderHook.java

+37
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package world.bentobox.bentobox.hooks;
22

3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.function.BiConsumer;
6+
37
import org.bukkit.Bukkit;
8+
import org.bukkit.Chunk;
49
import org.bukkit.Location;
510
import org.bukkit.Material;
611
import org.bukkit.entity.EntityType;
712
import org.bukkit.entity.Player;
813
import org.bukkit.event.EventHandler;
914
import org.bukkit.event.EventPriority;
1015
import org.bukkit.event.entity.EntityExplodeEvent;
16+
import org.eclipse.jdt.annotation.Nullable;
1117

1218
import dev.lone.itemsadder.api.CustomBlock;
1319
import world.bentobox.bentobox.BentoBox;
@@ -22,6 +28,19 @@
2228
* Hook to enable itemsadder blocks to be deleted when islands are deleted.
2329
* It also includes a flag to track explosion access
2430
*/
31+
/*
32+
* add some methods under CustomBlock#Advanced class.
33+
34+
public static void deleteAllCustomBlocksInChunk(Chunk chunk)
35+
36+
@Nullable
37+
public List<Location> getAllBlocksLocationsList(Chunk chunk)
38+
39+
@Nullable
40+
public Map<String, Location> getAllBlocksLocations(Chunk chunk)
41+
42+
public void runActionOnBlocks(Chunk chunk, BiConsumer<String, Location> action)
43+
*/
2544
public class ItemsAdderHook extends Hook {
2645

2746
/**
@@ -78,6 +97,24 @@ public void clearBlockInfo(Location location) {
7897
// CustomBlock.remove(location);
7998
}
8099

100+
public static void deleteAllCustomBlocksInChunk(Chunk chunk) {
101+
CustomBlock.Advanced.deleteAllCustomBlocksInChunk(chunk);
102+
}
103+
104+
@Nullable
105+
public List<Location> getAllBlocksLocationsList(Chunk chunk) {
106+
return CustomBlock.Advanced.getAllBlocksLocationsList(chunk);
107+
}
108+
109+
@Nullable
110+
public Map<Location, String> getAllBlocksLocations(Chunk chunk) {
111+
return CustomBlock.Advanced.getAllBlocksLocations(chunk);
112+
}
113+
114+
public void runActionOnBlocks(Chunk chunk, BiConsumer<String, Location> action) {
115+
CustomBlock.Advanced.runActionOnBlocks(chunk, action);
116+
}
117+
81118
class BlockInteractListener extends FlagListener {
82119

83120
/**

src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.util.concurrent.CompletableFuture;
99
import java.util.concurrent.ExecutionException;
1010

11+
import javax.annotation.Nonnull;
12+
1113
import org.bukkit.Bukkit;
1214
import org.bukkit.Chunk;
1315
import org.bukkit.Location;
@@ -33,11 +35,13 @@
3335
import org.bukkit.material.Colorable;
3436
import org.bukkit.scheduler.BukkitRunnable;
3537
import org.bukkit.util.BoundingBox;
38+
import org.eclipse.jdt.annotation.NonNull;
3639
import org.eclipse.jdt.annotation.Nullable;
3740

3841
import io.papermc.lib.PaperLib;
3942
import world.bentobox.bentobox.BentoBox;
4043
import world.bentobox.bentobox.api.addons.GameModeAddon;
44+
import world.bentobox.bentobox.api.hooks.Hook;
4145
import world.bentobox.bentobox.database.objects.IslandDeletion;
4246
import world.bentobox.bentobox.hooks.ItemsAdderHook;
4347
import world.bentobox.bentobox.hooks.SlimefunHook;
@@ -119,7 +123,8 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {
119123
return regenerateChunk(null, chunk.getWorld(), chunk.getX(), chunk.getZ());
120124
}
121125

122-
private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, World world, int chunkX, int chunkZ) {
126+
private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, @NonNull World world, int chunkX,
127+
int chunkZ) {
123128

124129
CompletableFuture<Chunk> seedWorldFuture = getSeedWorldChunk(world, chunkX, chunkZ);
125130

@@ -201,10 +206,12 @@ private void copyChunkDataToChunk(Chunk toChunk, Chunk fromChunk, BoundingBox li
201206
// Delete any 3rd party blocks
202207
Location loc = new Location(toChunk.getWorld(), baseX + x, y, baseZ + z);
203208
slimefunHook.ifPresent(hook -> hook.clearBlockInfo(loc, true));
204-
itemsAdderHook.ifPresent(hook -> hook.clearBlockInfo(loc));
209+
205210
}
206211
}
207212
}
213+
// Items Adder
214+
itemsAdderHook.ifPresent(hook -> ItemsAdderHook.deleteAllCustomBlocksInChunk(toChunk));
208215
// Entities
209216
Arrays.stream(fromChunk.getEntities()).forEach(e -> processEntity(e, e.getLocation().toVector().toLocation(toChunk.getWorld())));
210217

@@ -333,7 +340,8 @@ private boolean isEnded(int chunkX) {
333340
}
334341

335342
@SuppressWarnings("deprecation")
336-
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) {
343+
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, @Nonnull World world,
344+
int chunkX, int chunkZ) {
337345
CompletableFuture<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
338346
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
339347
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)
@@ -370,6 +378,7 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat
370378
double baseZ = chunk.getZ() << 4;
371379
int minHeight = chunk.getWorld().getMinHeight();
372380
int maxHeight = chunk.getWorld().getMaxHeight();
381+
Optional<Hook> slimefunHook = plugin.getHooks().getHook("Slimefun");
373382
for (int x = 0; x < 16; x++) {
374383
for (int z = 0; z < 16; z++) {
375384
if (!limitBox.contains(baseX + x, 0, baseZ + z)) {
@@ -383,12 +392,11 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat
383392
}
384393
// Delete any 3rd party blocks
385394
Location loc = new Location(chunk.getWorld(), baseX + x, y, baseZ + z);
386-
plugin.getHooks().getHook("Slimefun")
387-
.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
388-
plugin.getHooks().getHook("ItemsAdder")
389-
.ifPresent(hook -> ((ItemsAdderHook) hook).clearBlockInfo(loc));
395+
slimefunHook.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
390396
}
391397
}
392398
}
399+
// Items Adder
400+
plugin.getHooks().getHook("ItemsAdder").ifPresent(hook -> ItemsAdderHook.deleteAllCustomBlocksInChunk(chunk));
393401
}
394402
}

0 commit comments

Comments
 (0)