Skip to content

Commit

Permalink
Adds back in nether and end level calcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 19, 2019
1 parent 2cea8e9 commit b3d82a6
Showing 1 changed file with 52 additions and 24 deletions.
76 changes: 52 additions & 24 deletions src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.atomic.AtomicLong;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Material;
import org.bukkit.Tag;
Expand Down Expand Up @@ -45,10 +46,13 @@ public class CalcIslandLevel {

// Copy the limits hash map
private final HashMap<Material, Integer> limitCount;
private final List<World> worlds;
private final World world;

private int count;

private int total;


/**
* Calculate the island's level
Expand All @@ -63,6 +67,9 @@ public CalcIslandLevel(final Level addon, final Island island, final Runnable on
this.world = island.getWorld();
this.limitCount = new HashMap<>(addon.getSettings().getBlockLimits());
this.onExit = onExit;
this.worlds = new ArrayList<>();
this.worlds.add(world);


// Results go here
result = new Results();
Expand All @@ -73,19 +80,40 @@ public CalcIslandLevel(final Level addon, final Island island, final Runnable on
// Get chunks to scan
chunksToScan = getChunksToScan(island);
count = 0;
chunksToScan.forEach(c -> Util.getChunkAtAsync(world, c.x, c.z).thenAccept(ch -> {
ChunkSnapshot snapShot = ch.getChunkSnapshot();
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
this.scanChunk(snapShot);
count++;
if (count == chunksToScan.size()) {
this.tidyUp();
}
});
}));
// 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();
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
this.scanChunk(snapShot);
count++;
if (count == total) {
this.tidyUp();
}
});
}

private void scanChunk(ChunkSnapshot chunk) {
World chunkWorld = Bukkit.getWorld(chunk.getWorldName());
if (chunkWorld == null) return;
Expand Down Expand Up @@ -447,20 +475,20 @@ boolean eat(int charToEat) {
String func = str.substring(startPos, this.pos);
x = parseFactor();
switch (func) {
case "sqrt":
x = Math.sqrt(x);
break;
case "sin":
x = Math.sin(Math.toRadians(x));
break;
case "cos":
x = Math.cos(Math.toRadians(x));
break;
case "tan":
x = Math.tan(Math.toRadians(x));
break;
default:
throw new RuntimeException("Unknown function: " + func);
case "sqrt":
x = Math.sqrt(x);
break;
case "sin":
x = Math.sin(Math.toRadians(x));
break;
case "cos":
x = Math.cos(Math.toRadians(x));
break;
case "tan":
x = Math.tan(Math.toRadians(x));
break;
default:
throw new RuntimeException("Unknown function: " + func);
}
} else {
throw new RuntimeException("Unexpected: " + (char)ch);
Expand Down

0 comments on commit b3d82a6

Please sign in to comment.