This commit is contained in:
tastybento 2020-04-06 17:21:02 -07:00
commit 30783112b1
2 changed files with 38 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import world.bentobox.challenges.commands.ChallengesUserCommand;
import world.bentobox.challenges.commands.admin.Challenges;
import world.bentobox.challenges.commands.admin.ChallengesAdminCommand;
import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.handlers.ChallengeDataRequestHandler;
import world.bentobox.challenges.handlers.ChallengeListRequestHandler;
import world.bentobox.challenges.handlers.CompletedChallengesRequestHandler;
@ -361,6 +362,22 @@ public class ChallengesAddon extends Addon {
gameMode + "_challenge_locked_level_count",
user -> String.valueOf(this.challengesManager.getLevelCount(world) -
this.challengesManager.getUnlockedLevelCount(user, world)));
// Latest challenge level name placeholder
this.getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gameMode + "_challenge_latest_level_name",
user -> {
ChallengeLevel level = this.challengesManager.getLatestUnlockedLevel(user, world);
return level != null ? level.getFriendlyName() : "";
});
// Latest challenge level id placeholder
this.getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gameMode + "_challenge_latest_level_id",
user -> {
ChallengeLevel level = this.challengesManager.getLatestUnlockedLevel(user, world);
return level != null ? level.getUniqueId() : "";
});
}

View File

@ -1514,6 +1514,27 @@ public class ChallengesManager
}
/**
* This method returns latest ChallengeLevel object that is unlocked.
* @param user user who latest unlocked level must be returned.
* @param world World where level operates.
* @return ChallengeLevel for latest unlocked level.
*/
@Nullable
public ChallengeLevel getLatestUnlockedLevel(User user, World world)
{
LevelStatus lastStatus = null;
for (Iterator<LevelStatus> statusIterator = this.getAllChallengeLevelStatus(user, world).iterator();
statusIterator.hasNext() && (lastStatus == null || !lastStatus.isUnlocked());)
{
lastStatus = statusIterator.next();
}
return lastStatus != null ? lastStatus.getLevel() : null;
}
// ---------------------------------------------------------------------
// Section: Challenges related methods
// ---------------------------------------------------------------------