Skip to content

Commit

Permalink
Try to get WildStackers to work again.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 21, 2021
1 parent 49c7d8a commit 52ee815
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public void onEnable() {
// I only added support for counting blocks into the island level
// Someone else can PR if they want spawners added to the Leveling system :)
stackersEnabled = Bukkit.getPluginManager().getPlugin("WildStacker") != null;

if (stackersEnabled) {
log("Hooked into WildStackers.");
}
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.block.data.type.Slab;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -366,6 +367,8 @@ private int limitCount(Material md) {
* @param chunkSnapshot - the chunk to scan
*/
private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSnapshot, Chunk chunk) {
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
List<Vector> stackedBlocks = new ArrayList<>();
for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
if (chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || chunkSnapshot.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
Expand All @@ -379,7 +382,6 @@ private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSna
// Only count to the highest block in the world for some optimization
for (int y = 0; y < chunk.getWorld().getMaxHeight(); y++) {
BlockData blockData = chunkSnapshot.getBlockData(x, y, z);
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
// Slabs can be doubled, so check them twice
if (Tag.SLABS.isTagged(blockData.getMaterial())) {
Expand All @@ -390,14 +392,7 @@ private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSna
}
// Hook for Wild Stackers (Blocks Only) - this has to use the real chunk
if (addon.isStackersEnabled() && blockData.getMaterial() == Material.CAULDRON) {
Block cauldronBlock = chunk.getBlock(x, y, z);
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
int barrelAmt = WildStackerAPI.getBarrelAmount(cauldronBlock);
for (int _x = 0; _x < barrelAmt; _x++) {
checkBlock(barrel.getType(), belowSeaLevel);
}
}
stackedBlocks.add(new Vector(x,y,z));
}
// Add the value of the block's material
checkBlock(blockData.getMaterial(), belowSeaLevel);
Expand All @@ -410,7 +405,21 @@ private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSna
tidyUp();
}
// Complete the future - this must go back onto the primary thread to exit async otherwise subsequent actions will be async
Bukkit.getScheduler().runTask(addon.getPlugin(),() -> result.complete(true));
Bukkit.getScheduler().runTask(addon.getPlugin(),() -> {
// Deal with any stacked blocks
stackedBlocks.forEach(v -> {
Block cauldronBlock = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
int barrelAmt = WildStackerAPI.getBarrelAmount(cauldronBlock);
for (int _x = 0; _x < barrelAmt; _x++) {
checkBlock(barrel.getType(), belowSeaLevel);
}
}
});
result.complete(true);
});
}

/**
Expand Down Expand Up @@ -501,7 +510,10 @@ private Collection<String> sortedReport(int total, Multiset<Material> materialCo
}


private void tidyUp() {
/**
* Finalizes the calculations and makes the report
*/
public void tidyUp() {
// Finalize calculations
results.rawBlockCount.addAndGet((long)(results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/world/bentobox/level/calculators/Pipeliner.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ private void scanChunk(IslandLevelCalculator iD) {
} else {
// Done
inProcessQueue.remove(iD);
// Chunk finished
// This was the last chunk
iD.tidyUp();
iD.getR().complete(iD.getResults());
}
});
Expand Down

0 comments on commit 52ee815

Please sign in to comment.