Skip to content

Commit

Permalink
Fixes #263
Browse files Browse the repository at this point in the history
Thanks to @sgdc3 who found my mistake with checking if challenges exists when opening GUI.
  • Loading branch information
BONNe committed Nov 28, 2020
1 parent b4e62f1 commit 93f07b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2088,26 +2088,26 @@ public void deleteChallengeLevel(ChallengeLevel challengeLevel)
/**
* This method returns if in given world has any stored challenge or level.
* @param world World that needs to be checked
* @return <code>true</code> if world has any challenge or level, otherwise <code>false</code>
* @return {@code true} if world has any challenge or level, otherwise {@code false}
*/
public boolean hasAnyChallengeData(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).filter(gameMode ->
this.hasAnyChallengeData(gameMode.getDescription().getName())).isPresent();
this.hasAnyChallengeData(gameMode.getDescription().getName())).isPresent();
}


/**
* This method returns if in given gameMode has any stored challenge or level.
* @param gameMode GameMode addon name that needs to be checked
* @return <code>true</code> if gameMode has any challenge or level, otherwise <code>false</code>
* @return {@code true} if gameMode has any challenge or level, otherwise {@code false}
*/
public boolean hasAnyChallengeData(@NonNull String gameMode)
{
return this.challengeDatabase.loadObjects().stream().anyMatch(
challenge -> challenge.matchGameMode(gameMode)) ||
this.levelDatabase.loadObjects().stream().anyMatch(
level -> level.matchGameMode(gameMode));
return this.challengeCacheData.values().stream().anyMatch(challenge -> challenge.matchGameMode(gameMode)) ||
this.levelCacheData.values().stream().anyMatch(level -> level.matchGameMode(gameMode)) ||
this.challengeDatabase.loadObjects().stream().anyMatch(challenge -> challenge.matchGameMode(gameMode)) ||
this.levelDatabase.loadObjects().stream().anyMatch(level -> level.matchGameMode(gameMode));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public ChallengesGUI(ChallengesAddon addon,
break;
}
}

this.containsChallenges = this.challengesManager.hasAnyChallengeData(this.world);
}

// ---------------------------------------------------------------------
Expand All @@ -76,7 +78,7 @@ public ChallengesGUI(ChallengesAddon addon,
public void build()
{
// Do not open gui if there is no challenges.
if (!this.challengesManager.hasAnyChallengeData(this.world))
if (!this.containsChallenges)
{
this.addon.logError("There are no challenges set up!");
this.user.sendMessage("challenges.errors.no-challenges");
Expand Down Expand Up @@ -518,4 +520,9 @@ else if (level.isUnlocked())
* Challenge Manager object.
*/
private ChallengesManager challengesManager;

/**
* This boolean indicates if in the world there exist challenges for displaying in GUI.
*/
private final boolean containsChallenges;
}

0 comments on commit 93f07b9

Please sign in to comment.