From 3d0e1b09220216744e8a3eb0ca0571f299fb5ba0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 5 May 2020 16:56:22 -0700 Subject: [PATCH] Recount will count Nether and End blocks. Fixes https://github.com/BentoBoxWorld/Limits/issues/80 --- .../bentobox/limits/commands/LimitsCalc.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/limits/commands/LimitsCalc.java b/src/main/java/world/bentobox/limits/commands/LimitsCalc.java index 683af85..2660067 100644 --- a/src/main/java/world/bentobox/limits/commands/LimitsCalc.java +++ b/src/main/java/world/bentobox/limits/commands/LimitsCalc.java @@ -38,9 +38,20 @@ public class LimitsCalc { private final User sender; private final Set> chunksToScan; private int count; + private int chunksToScanCount; + private BentoBox plugin; + /** + * Perform a count of all limited blocks or entities on an island + * @param world - game world to scan + * @param instance - BentoBox + * @param targetPlayer - target player's island + * @param addon - addon instance + * @param sender - requester of the count + */ LimitsCalc(World world, BentoBox instance, UUID targetPlayer, Limits addon, User sender) { + this.plugin = instance; this.addon = addon; this.island = instance.getIslands().getIsland(world, targetPlayer); this.bll = addon.getBlockLimitListener(); @@ -52,19 +63,36 @@ public class LimitsCalc { // Get chunks to scan chunksToScan = getChunksToScan(island); count = 0; - chunksToScan.forEach(c -> Util.getChunkAtAsync(world, c.x, c.z).thenAccept(ch -> { + + boolean isNether = plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world); + boolean isEnd = plugin.getIWM().isEndGenerate(world) && plugin.getIWM().isEndIslands(world); + // Calculate how many chunks need to be scanned + chunksToScanCount = chunksToScan.size() + (isNether ? chunksToScan.size():0) + (isEnd ? chunksToScan.size():0); + chunksToScan.forEach(c -> { + asyncScan(world, c); + if (isNether) asyncScan(plugin.getIWM().getNetherWorld(world), c); + if (isEnd) asyncScan(plugin.getIWM().getEndWorld(world), c); + }); + + } + + + + private void asyncScan(World world2, Pair c) { + Util.getChunkAtAsync(world2, c.x, c.z).thenAccept(ch -> { ChunkSnapshot snapShot = ch.getChunkSnapshot(); Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> { this.scanChunk(snapShot); count++; - if (count == chunksToScan.size()) { + if (count == chunksToScanCount) { this.tidyUp(); } }); - })); - + }); } + + private void scanChunk(ChunkSnapshot chunk) { for (int x = 0; x < 16; x++) { // Check if the block coordinate is inside the protection zone and if not, don't count it