Skip to content

Commit

Permalink
Recount will count Nether and End blocks.
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
tastybento committed May 5, 2020
1 parent eb065d3 commit 3d0e1b0
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/main/java/world/bentobox/limits/commands/LimitsCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ public class LimitsCalc {
private final User sender;
private final Set<Pair<Integer, Integer>> 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();
Expand All @@ -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<Integer, Integer> 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
Expand Down

0 comments on commit 3d0e1b0

Please sign in to comment.