From 52ee81501b51ac72cb04dc267ad174c038a27d63 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 20 Feb 2021 19:07:08 -0800 Subject: [PATCH] Try to get WildStackers to work again. --- src/main/java/world/bentobox/level/Level.java | 4 ++- .../calculators/IslandLevelCalculator.java | 34 +++++++++++++------ .../bentobox/level/calculators/Pipeliner.java | 3 ++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index dac985d..91b498d 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -95,7 +95,9 @@ public class Level extends Addon implements Listener { // 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 diff --git a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java index 34411ba..1b97489 100644 --- a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java +++ b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java @@ -24,6 +24,7 @@ import org.bukkit.block.data.BlockData; 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; @@ -366,6 +367,8 @@ public class IslandLevelCalculator { * @param chunkSnapshot - the chunk to scan */ private void scanAsync(CompletableFuture result, ChunkSnapshot chunkSnapshot, Chunk chunk) { + int seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld()); + List 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) { @@ -379,7 +382,6 @@ public class IslandLevelCalculator { // 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())) { @@ -390,14 +392,7 @@ public class IslandLevelCalculator { } // 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); @@ -410,7 +405,21 @@ public class IslandLevelCalculator { 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); + }); } /** @@ -501,7 +510,10 @@ public class IslandLevelCalculator { } - 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())); diff --git a/src/main/java/world/bentobox/level/calculators/Pipeliner.java b/src/main/java/world/bentobox/level/calculators/Pipeliner.java index ae8582a..83af5e8 100644 --- a/src/main/java/world/bentobox/level/calculators/Pipeliner.java +++ b/src/main/java/world/bentobox/level/calculators/Pipeliner.java @@ -100,6 +100,9 @@ public class Pipeliner { } else { // Done inProcessQueue.remove(iD); + // Chunk finished + // This was the last chunk + iD.tidyUp(); iD.getR().complete(iD.getResults()); } });