Fixes issue with initial level calculations and reporting.

https://github.com/BentoBoxWorld/Level/issues/189
This commit is contained in:
tastybento 2020-09-12 11:59:45 -07:00
parent b5e161d59e
commit 0d1a10ff6f
3 changed files with 8 additions and 16 deletions

View File

@ -165,6 +165,8 @@ public class IslandLevelCalculator {
duration = System.currentTimeMillis(); duration = System.currentTimeMillis();
chunksToCheck = getChunksToScan(island); chunksToCheck = getChunksToScan(island);
this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits()); this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits());
// Get the initial island level
results.initialLevel.set(addon.getInitialIslandLevel(island));
} }
/** /**
@ -175,7 +177,7 @@ public class IslandLevelCalculator {
private long calculateLevel(long blockAndDeathPoints) { private long calculateLevel(long blockAndDeathPoints) {
String calcString = addon.getSettings().getLevelCalc(); String calcString = addon.getSettings().getLevelCalc();
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost", String.valueOf(this.addon.getSettings().getLevelCost())); 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);
} }
/** /**
@ -242,11 +244,7 @@ public class IslandLevelCalculator {
reportLines.add("Initial island level = " + (0L - addon.getManager().getInitialLevel(island))); reportLines.add("Initial island level = " + (0L - addon.getManager().getInitialLevel(island)));
} }
reportLines.add("Previous level = " + addon.getManager().getIslandLevel(island.getWorld(), island.getOwner())); 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); reportLines.add(LINE_BREAK);
int total = 0; int total = 0;
if (!results.uwCount.isEmpty()) { if (!results.uwCount.isEmpty()) {
@ -531,12 +529,6 @@ public class IslandLevelCalculator {
} }
this.results.level.set(calculateLevel(blockAndDeathPoints)); 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 // Calculate how many points are required to get to the next level
long nextLevel = this.results.level.get(); long nextLevel = this.results.level.get();
long blocks = blockAndDeathPoints; long blocks = blockAndDeathPoints;

View File

@ -36,8 +36,8 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("") @ConfigComment("")
@ConfigComment("Zero island levels on new island or island reset") @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 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("If false, the player's starter island blocks will count towards their level.")
@ConfigComment("This will reduce CPU if it isn't used.") @ConfigComment("This will reduce CPU if false.")
@ConfigEntry(path = "zero-new-island-levels") @ConfigEntry(path = "zero-new-island-levels")
private boolean zeroNewIslandLevels = true; private boolean zeroNewIslandLevels = true;

View File

@ -17,8 +17,8 @@ calculation-timeout: 5
# #
# Zero island levels on new island or island reset # 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 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. # If this is false, the player's starter island blocks will count towards their level.
# This will reduce CPU if it isn't used. # This will reduce CPU if false.
zero-new-island-levels: true zero-new-island-levels: true
# #
# Calculate island level on login # Calculate island level on login