Rationalize output of IslandLevelCalculatedEvent

Level is now the fully calculated level, i.e., what the user sees. The
initial level is subtracted if the config settings are set to do that.

https://github.com/BentoBoxWorld/Level/issues/188
This commit is contained in:
tastybento 2020-09-12 08:47:09 -07:00
parent aed06b74c0
commit b5e161d59e
3 changed files with 9 additions and 13 deletions

View File

@ -205,11 +205,7 @@ public class LevelsManager {
keyValues.put("eventName", "IslandLevelCalculatedEvent"); keyValues.put("eventName", "IslandLevelCalculatedEvent");
keyValues.put("targetPlayer", targetPlayer); keyValues.put("targetPlayer", targetPlayer);
keyValues.put("islandUUID", island.getUniqueId()); keyValues.put("islandUUID", island.getUniqueId());
if (addon.getSettings().isZeroNewIslandLevels()) {
keyValues.put("level", results.getLevel() - results.getInitialLevel());
} else {
keyValues.put("level", results.getLevel()); keyValues.put("level", results.getLevel());
}
keyValues.put("pointsToNextLevel", results.getPointsToNextLevel()); keyValues.put("pointsToNextLevel", results.getPointsToNextLevel());
keyValues.put("deathHandicap", results.getDeathHandicap()); keyValues.put("deathHandicap", results.getDeathHandicap());
keyValues.put("initialLevel", results.getInitialLevel()); keyValues.put("initialLevel", results.getInitialLevel());
@ -542,12 +538,7 @@ public class LevelsManager {
Island island = addon.getIslands().getIsland(world, owner); Island island = addon.getIslands().getIsland(world, owner);
if (island == null) return; if (island == null) return;
IslandLevels ld = levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new); IslandLevels ld = levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new);
// Remove the initial level
if (addon.getSettings().isZeroNewIslandLevels()) {
ld.setLevel(r.getLevel() - ld.getInitialLevel());
} else {
ld.setLevel(r.getLevel()); ld.setLevel(r.getLevel());
}
ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem))); ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem)));
ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem))); ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem)));
ld.setPointsToNextLevel(r.getPointsToNextLevel()); ld.setPointsToNextLevel(r.getPointsToNextLevel());

View File

@ -531,6 +531,12 @@ 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

@ -45,8 +45,7 @@ public class IslandLevelCalculatedEvent extends IslandBaseEvent {
} }
/** /**
* Get the island's initial level. It may be zero if it was never calculated * Get the island's initial level. It may be zero if it was never calculated.
* or if a player was registered to the island after it was made.
* @return initial level of island as calculated when the island was created. * @return initial level of island as calculated when the island was created.
*/ */
public long getInitialLevel() { public long getInitialLevel() {