diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java
index 4524ac1..ec717c6 100644
--- a/src/main/java/world/bentobox/challenges/ChallengesManager.java
+++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java
@@ -2088,26 +2088,26 @@ public class ChallengesManager
/**
* This method returns if in given world has any stored challenge or level.
* @param world World that needs to be checked
- * @return true
if world has any challenge or level, otherwise false
+ * @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 true
if gameMode has any challenge or level, otherwise false
+ * @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));
}
diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java
index 38005ad..222e7bb 100644
--- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java
+++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java
@@ -62,6 +62,8 @@ public class ChallengesGUI extends CommonGUI
break;
}
}
+
+ this.containsChallenges = this.challengesManager.hasAnyChallengeData(this.world);
}
// ---------------------------------------------------------------------
@@ -76,7 +78,7 @@ public class ChallengesGUI extends CommonGUI
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");
@@ -518,4 +520,9 @@ public class ChallengesGUI extends CommonGUI
* Challenge Manager object.
*/
private ChallengesManager challengesManager;
+
+ /**
+ * This boolean indicates if in the world there exist challenges for displaying in GUI.
+ */
+ private final boolean containsChallenges;
}