Implement 2 new placeholders.
This commit is contained in:
BONNe 2020-06-19 11:36:26 +03:00 committed by BONNe1704
parent dd8834f1df
commit e85b687e36
2 changed files with 33 additions and 0 deletions

View File

@ -388,6 +388,24 @@ public class ChallengesAddon extends Addon {
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);
});
}

View File

@ -1786,6 +1786,21 @@ public class ChallengesManager
}
/**
* 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
// ---------------------------------------------------------------------