Skip to content

Commit

Permalink
Rationalize output of IslandLevelCalculatedEvent
Browse files Browse the repository at this point in the history
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.

#188
  • Loading branch information
tastybento committed Sep 12, 2020
1 parent aed06b7 commit b5e161d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/main/java/world/bentobox/level/LevelsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ private boolean fireIslandLevelCalcEvent(UUID targetPlayer, Island island, Resul
keyValues.put("eventName", "IslandLevelCalculatedEvent");
keyValues.put("targetPlayer", targetPlayer);
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("deathHandicap", results.getDeathHandicap());
keyValues.put("initialLevel", results.getInitialLevel());
Expand Down Expand Up @@ -542,12 +538,7 @@ private void setIslandResults(World world, @NonNull UUID owner, Results r) {
Island island = addon.getIslands().getIsland(world, owner);
if (island == null) return;
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.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem)));
ld.setPointsToNextLevel(r.getPointsToNextLevel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public int getDeathHandicap() {
}

/**
* 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.
* Get the island's initial level. It may be zero if it was never calculated.
* @return initial level of island as calculated when the island was created.
*/
public long getInitialLevel() {
Expand Down

0 comments on commit b5e161d

Please sign in to comment.