mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-27 20:46:19 +01:00
Adds back in nether and end level calcs.
https://github.com/BentoBoxWorld/Level/issues/101
This commit is contained in:
parent
2cea8e942f
commit
b3d82a6456
@ -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
|
||||||
ChunkSnapshot snapShot = ch.getChunkSnapshot();
|
total = chunksToScan.size();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
// Add nether world scanning
|
||||||
this.scanChunk(snapShot);
|
if (addon.getSettings().isNether()) {
|
||||||
count++;
|
World netherWorld = addon.getPlugin().getIWM().getNetherWorld(world);
|
||||||
if (count == chunksToScan.size()) {
|
if (netherWorld != null) {
|
||||||
this.tidyUp();
|
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) {
|
private void scanChunk(ChunkSnapshot chunk) {
|
||||||
@ -447,20 +475,20 @@ public class CalcIslandLevel {
|
|||||||
String func = str.substring(startPos, this.pos);
|
String func = str.substring(startPos, this.pos);
|
||||||
x = parseFactor();
|
x = parseFactor();
|
||||||
switch (func) {
|
switch (func) {
|
||||||
case "sqrt":
|
case "sqrt":
|
||||||
x = Math.sqrt(x);
|
x = Math.sqrt(x);
|
||||||
break;
|
break;
|
||||||
case "sin":
|
case "sin":
|
||||||
x = Math.sin(Math.toRadians(x));
|
x = Math.sin(Math.toRadians(x));
|
||||||
break;
|
break;
|
||||||
case "cos":
|
case "cos":
|
||||||
x = Math.cos(Math.toRadians(x));
|
x = Math.cos(Math.toRadians(x));
|
||||||
break;
|
break;
|
||||||
case "tan":
|
case "tan":
|
||||||
x = Math.tan(Math.toRadians(x));
|
x = Math.tan(Math.toRadians(x));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown function: " + func);
|
throw new RuntimeException("Unknown function: " + func);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unexpected: " + (char)ch);
|
throw new RuntimeException("Unexpected: " + (char)ch);
|
||||||
|
Loading…
Reference in New Issue
Block a user