From 0d1a10ff6faad20a6f98914b9ec98fc7c424b2ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 12 Sep 2020 11:59:45 -0700 Subject: [PATCH] Fixes issue with initial level calculations and reporting. https://github.com/BentoBoxWorld/Level/issues/189 --- .../level/calculators/IslandLevelCalculator.java | 16 ++++------------ .../bentobox/level/config/ConfigSettings.java | 4 ++-- src/main/resources/config.yml | 4 ++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java index ca1c243..a618fd3 100644 --- a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java +++ b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java @@ -165,6 +165,8 @@ public class IslandLevelCalculator { duration = System.currentTimeMillis(); chunksToCheck = getChunksToScan(island); 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) { 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); } /** @@ -242,11 +244,7 @@ public class IslandLevelCalculator { 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()) { @@ -531,12 +529,6 @@ public class IslandLevelCalculator { } 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; diff --git a/src/main/java/world/bentobox/level/config/ConfigSettings.java b/src/main/java/world/bentobox/level/config/ConfigSettings.java index ebebae7..cbf2752 100644 --- a/src/main/java/world/bentobox/level/config/ConfigSettings.java +++ b/src/main/java/world/bentobox/level/config/ConfigSettings.java @@ -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; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2ea0343..c5527fd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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