Adds back in nether and end level calcs.

https://github.com/BentoBoxWorld/Level/issues/101
This commit is contained in:
tastybento 2019-11-19 13:06:29 -08:00
parent 2cea8e942f
commit b3d82a6456

View File

@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
@ -45,10 +46,13 @@ public class CalcIslandLevel {
// Copy the limits hash map // Copy the limits hash map
private final HashMap<Material, Integer> limitCount; private final HashMap<Material, Integer> limitCount;
private final List<World> worlds;
private final World world; private final World world;
private int count; private int count;
private int total;
/** /**
* Calculate the island's level * Calculate the island's level
@ -63,6 +67,9 @@ public class CalcIslandLevel {
this.world = island.getWorld(); this.world = island.getWorld();
this.limitCount = new HashMap<>(addon.getSettings().getBlockLimits()); this.limitCount = new HashMap<>(addon.getSettings().getBlockLimits());
this.onExit = onExit; this.onExit = onExit;
this.worlds = new ArrayList<>();
this.worlds.add(world);
// Results go here // Results go here
result = new Results(); result = new Results();
@ -73,17 +80,38 @@ public class CalcIslandLevel {
// Get chunks to scan // Get chunks to scan
chunksToScan = getChunksToScan(island); chunksToScan = getChunksToScan(island);
count = 0; count = 0;
chunksToScan.forEach(c -> Util.getChunkAtAsync(world, c.x, c.z).thenAccept(ch -> { // Total number of chunks to scan
total = chunksToScan.size();
// Add nether world scanning
if (addon.getSettings().isNether()) {
World netherWorld = addon.getPlugin().getIWM().getNetherWorld(world);
if (netherWorld != null) {
this.worlds.add(netherWorld);
total += chunksToScan.size();
}
}
// Add End world scanning
if (addon.getSettings().isEnd()) {
World endWorld = addon.getPlugin().getIWM().getEndWorld(world);
if (endWorld != null) {
this.worlds.add(endWorld);
total += chunksToScan.size();
}
}
chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::getChunk)));
}
private void getChunk(Chunk ch) {
ChunkSnapshot snapShot = ch.getChunkSnapshot(); ChunkSnapshot snapShot = ch.getChunkSnapshot();
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> { Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
this.scanChunk(snapShot); this.scanChunk(snapShot);
count++; count++;
if (count == chunksToScan.size()) { if (count == total) {
this.tidyUp(); this.tidyUp();
} }
}); });
}));
} }
private void scanChunk(ChunkSnapshot chunk) { private void scanChunk(ChunkSnapshot chunk) {