Skip to content

Commit

Permalink
Enabled option to include nether and end islands in level calc
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 8, 2019
1 parent 9045223 commit d5e5410
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public class CalcIslandLevel {

private final Set<Pair<Integer, Integer>> chunksToScan;
private final Island island;
private final World world;
private final Results result;
private final Runnable onExit;

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


/**
Expand All @@ -59,7 +60,17 @@ public class CalcIslandLevel {
public CalcIslandLevel(final Level addon, final Island island, final Runnable onExit) {
this.addon = addon;
this.island = island;
this.world = island.getCenter().getWorld();
this.world = island.getWorld();
this.worlds = new ArrayList<>();
this.worlds.add(world);
if (addon.getSettings().isNether()) {
World netherWorld = addon.getPlugin().getIWM().getNetherWorld(world);
if (netherWorld != null) this.worlds.add(netherWorld);
}
if (addon.getSettings().isEnd()) {
World endWorld = addon.getPlugin().getIWM().getEndWorld(world);
if (endWorld != null) this.worlds.add(endWorld);
}
this.limitCount = new HashMap<>(addon.getSettings().getBlockLimits());
this.onExit = onExit;

Expand Down Expand Up @@ -88,12 +99,14 @@ public CalcIslandLevel(final Level addon, final Island island, final Runnable on
// Add chunk snapshots to the list
while (it.hasNext() && chunkSnapshot.size() < MAX_CHUNKS) {
Pair<Integer, Integer> pair = it.next();
if (!world.isChunkLoaded(pair.x, pair.z)) {
world.loadChunk(pair.x, pair.z);
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
world.unloadChunk(pair.x, pair.z);
} else {
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
for (World world : worlds) {
if (!world.isChunkLoaded(pair.x, pair.z)) {
world.loadChunk(pair.x, pair.z);
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
world.unloadChunk(pair.x, pair.z);
} else {
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
}
}
it.remove();
}
Expand All @@ -117,6 +130,10 @@ private void checkChunksAsync(final Set<ChunkSnapshot> chunkSnapshot) {
}

private void scanChunk(ChunkSnapshot chunk) {
World chunkWorld = Bukkit.getWorld(chunk.getWorldName());
if (chunkWorld == null) return;
int maxHeight = chunkWorld.getMaxHeight();

for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
Expand All @@ -128,9 +145,9 @@ private void scanChunk(ChunkSnapshot chunk) {
continue;
}

for (int y = 0; y < island.getCenter().getWorld().getMaxHeight(); y++) {
for (int y = 0; y < maxHeight; y++) {
BlockData blockData = chunk.getBlockData(x, y, z);
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(world);
int seaHeight = addon.getPlugin().getIWM().getSeaHeight(chunkWorld);
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
// Slabs can be doubled, so check them twice
if (Tag.SLABS.isTagged(blockData.getMaterial())) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/world/bentobox/level/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

public class Settings {

private Level level;
private boolean sumTeamDeaths;
private Map<Material, Integer> blockLimits = new HashMap<>();
private Map<Material, Integer> blockValues = new HashMap<>();
Expand All @@ -25,7 +26,7 @@ public class Settings {
private List<String> gameModes = new ArrayList<>();

public Settings(Level level) {

this.level = level;
level.saveDefaultConfig();

// GameModes
Expand Down Expand Up @@ -190,4 +191,18 @@ public List<String> getGameModes() {
return gameModes;
}

/**
* @return if the nether island should be included in the level calc or not
*/
public boolean isNether() {
return level.getConfig().getBoolean("nether");
}

/**
* @return if the end island should be included in the level calc or not
*/
public boolean isEnd() {
return level.getConfig().getBoolean("end");
}

}
10 changes: 10 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ game-modes:
# Players with the permission askyblock.island.multiplier.# will have their blocks
# multiplied in value by that amount.

# Include nether island in level calculations.
# Warning: Enabling this mid-game will give players with an island a jump in
# island level. New islands will be correctly zeroed.
nether: false

# Include end island in level calculations
# Warning: Enabling this mid-game will give players with an island a jump in
# island level. New islands will be correctly zeroed.
end: false

# Underwater block multiplier
# If blocks are below sea-level, they can have a higher value. e.g. 2x
# Promotes under-water development if there is a sea. Value can be fractional.
Expand Down

0 comments on commit d5e5410

Please sign in to comment.