Skip to content

Commit

Permalink
Fix issue #23 - ChallengesToDo shows wrong number.
Browse files Browse the repository at this point in the history
This issue happens, because LevelStatus keeps record about current level completion. So "novice" level knows how much it needs to unlock the next level and so on.
My proposed fix is just workaround of current behavior, but I think there is necessary better rework of LevelStatus object.
  • Loading branch information
BONNe committed Dec 17, 2018
1 parent cd503d7 commit b37fee1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ private void createItem(PanelBuilder panelBuilder, Challenges challenge) {
}

private void addNavigation(PanelBuilder panelBuilder) {
// TODO: This if fix for wrong getNumberOfChallengesStillToDo() issue. #23
LevelStatus previousStatus = null;

// Add navigation to other levels
for (LevelStatus status: manager.getChallengeLevelStatus(user, world)) {
if (status.getLevel().getUniqueId().equals(level)) {
// Skip if this is the current level
previousStatus = status;
continue;
}
// Create a nice name for the level
Expand All @@ -140,10 +144,12 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(manager.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(status.getNumberOfChallengesStillToDo()), "[thisLevel]", previousLevelName)))
.description(manager.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.build();
panelBuilder.item(item);
}

previousStatus = status;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ private void createItem(PanelBuilder panelBuilder, Challenges challenge) {
}

private void addNavigation(PanelBuilder panelBuilder) {
// TODO: This if fix for wrong getNumberOfChallengesStillToDo() issue. #23
LevelStatus previousStatus = null;

// Add navigation to other levels
for (LevelStatus status: manager.getChallengeLevelStatus(requester, world)) {
if (status.getLevel().getUniqueId().equalsIgnoreCase(level)) {
// Skip if this is the current level
previousStatus = status;
continue;
}
// Create a nice name for the level
Expand All @@ -195,10 +199,12 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(manager.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(status.getNumberOfChallengesStillToDo()), "[thisLevel]", previousLevelName)))
.description(manager.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.build();
panelBuilder.item(item);
}

previousStatus = status;
}
}

Expand Down

0 comments on commit b37fee1

Please sign in to comment.