Skip to content

Commit

Permalink
Fixes issue with initial level calculations and reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 12, 2020
1 parent b5e161d commit 0d1a10f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Resul
duration = System.currentTimeMillis();
chunksToCheck = getChunksToScan(island);
this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits());
// Get the initial island level
results.initialLevel.set(addon.getInitialIslandLevel(island));
}

/**
Expand All @@ -175,7 +177,7 @@ public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Resul
private long calculateLevel(long blockAndDeathPoints) {
String calcString = addon.getSettings().getLevelCalc();
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost", String.valueOf(this.addon.getSettings().getLevelCost()));
return (long)eval(withValues) - this.island.getLevelHandicap() - results.initialLevel.get();
return (long)eval(withValues) - this.island.getLevelHandicap() - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
}

/**
Expand Down Expand Up @@ -242,11 +244,7 @@ private List<String> getReport() {
reportLines.add("Initial island level = " + (0L - addon.getManager().getInitialLevel(island)));
}
reportLines.add("Previous level = " + addon.getManager().getIslandLevel(island.getWorld(), island.getOwner()));
if (addon.getSettings().isZeroNewIslandLevels()) {
reportLines.add("New level = " + (results.getLevel() - addon.getManager().getInitialLevel(island)));
} else {
reportLines.add("New level = " + results.getLevel());
}
reportLines.add("New level = " + results.getLevel());
reportLines.add(LINE_BREAK);
int total = 0;
if (!results.uwCount.isEmpty()) {
Expand Down Expand Up @@ -531,12 +529,6 @@ private void tidyUp() {
}
this.results.level.set(calculateLevel(blockAndDeathPoints));

// Adjust for initial level
if (addon.getSettings().isZeroNewIslandLevels()) {
long oldLevel = this.results.level.get();
this.results.level.set(oldLevel - this.results.initialLevel.get());
}

// Calculate how many points are required to get to the next level
long nextLevel = this.results.level.get();
long blocks = blockAndDeathPoints;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/level/config/ConfigSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("")
@ConfigComment("Zero island levels on new island or island reset")
@ConfigComment("If true, Level will calculate the starter island's level and remove it from any future level calculations.")
@ConfigComment("If false, the player's starter island and will count towards their level.")
@ConfigComment("This will reduce CPU if it isn't used.")
@ConfigComment("If false, the player's starter island blocks will count towards their level.")
@ConfigComment("This will reduce CPU if false.")
@ConfigEntry(path = "zero-new-island-levels")
private boolean zeroNewIslandLevels = true;

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ calculation-timeout: 5
#
# Zero island levels on new island or island reset
# If true, Level will calculate the starter island's level and remove it from any future level calculations.
# If this is false, the player's starter island and will count towards their level.
# This will reduce CPU if it isn't used.
# If this is false, the player's starter island blocks will count towards their level.
# This will reduce CPU if false.
zero-new-island-levels: true
#
# Calculate island level on login
Expand Down

0 comments on commit 0d1a10f

Please sign in to comment.