Skip to content

Commit

Permalink
Fixes #244
Browse files Browse the repository at this point in the history
Implement 2 new placeholders.
  • Loading branch information
BONNe committed Jun 19, 2020
1 parent dd8834f commit e85b687
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,24 @@ private void registerPlaceholders(GameModeAddon gameModeAddon)
ChallengeLevel level = this.challengesManager.getLatestUnlockedLevel(user, world);
return level != null ? level.getUniqueId() : "";
});

// Completed challenge count in latest level
this.getPlugin().getPlaceholdersManager().registerPlaceholder(gameModeAddon,
addonName + "_latest_level_completed_count",
user -> {
ChallengeLevel level = this.challengesManager.getLatestUnlockedLevel(user, world);
return String.valueOf(level != null ?
this.challengesManager.getLevelCompletedChallengeCount(user, world, level) : 0);
});

// Uncompleted challenge count in latest level
this.getPlugin().getPlaceholdersManager().registerPlaceholder(gameModeAddon,
addonName + "_latest_level_uncompleted_count",
user -> {
ChallengeLevel level = this.challengesManager.getLatestUnlockedLevel(user, world);
return String.valueOf(level != null ?
level.getChallenges().size() - this.challengesManager.getLevelCompletedChallengeCount(user, world, level) : 0);
});
}


Expand Down
15 changes: 15 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,21 @@ public long getTotalChallengeCompletionCount(User user, World world)
}


/**
* This method returns completed challenge count in given level.
* @param user User which should be checked
* @param world World where challenges are operating
* @param level Level which challenges must be checked.
* @return Number of completed challenges in given level.
*/
public long getLevelCompletedChallengeCount(User user, World world, ChallengeLevel level)
{
return this.getLevelChallenges(level).stream().
filter(challenge -> this.getChallengeTimes(user, world, challenge) > 0).
count();
}


// ---------------------------------------------------------------------
// Section: Level related methods
// ---------------------------------------------------------------------
Expand Down

0 comments on commit e85b687

Please sign in to comment.