Skip to content

Commit

Permalink
Add protective code in ChallengesManager to avoid getting challenges …
Browse files Browse the repository at this point in the history
…for non-existing world. #622
  • Loading branch information
BONNe committed Apr 2, 2019
1 parent e33db6e commit d5e7549
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,19 @@ public List<LevelStatus> getAllChallengeLevelStatus(User user, World world)
* @param world - the world to check
* @return List of challenge names
*/
public List<String> getAllChallengesNames(World world)
public List<String> getAllChallengesNames(@NonNull World world)
{
String worldName = Util.getWorld(world).getName();
World gameWorld = Util.getWorld(world);

if (gameWorld == null)
{
return Collections.emptyList();
}

// TODO: Probably need to check also database.
return this.challengeCacheData.values().stream().
sorted(Comparator.comparing(Challenge::getOrder)).
filter(challenge -> challenge.getUniqueId().startsWith(worldName)).
filter(challenge -> challenge.getUniqueId().startsWith(gameWorld.getName())).
map(Challenge::getUniqueId).
collect(Collectors.toList());
}
Expand All @@ -1054,12 +1060,18 @@ public List<String> getAllChallengesNames(World world)
* @param world - the world to check
* @return List of challenges
*/
public List<Challenge> getAllChallenges(World world)
public List<Challenge> getAllChallenges(@NonNull World world)
{
String worldName = Util.getWorld(world).getName();
World gameWorld = Util.getWorld(world);

if (gameWorld == null)
{
return Collections.emptyList();
}

// TODO: Probably need to check also database.
return this.challengeCacheData.values().stream().
filter(challenge -> challenge.getUniqueId().startsWith(worldName)).
filter(challenge -> challenge.getUniqueId().startsWith(gameWorld.getName())).
sorted(Comparator.comparing(Challenge::getOrder)).
collect(Collectors.toList());
}
Expand Down Expand Up @@ -1198,9 +1210,16 @@ public void deleteChallenge(Challenge challenge)
* @param world for which levels must be searched.
* @return List with challenges in given world.
*/
public List<ChallengeLevel> getLevels(World world)
public List<ChallengeLevel> getLevels(@NonNull World world)
{
return this.getLevels(Util.getWorld(world).getName());
world = Util.getWorld(world);

if (world == null)
{
return Collections.emptyList();
}

return this.getLevels(world.getName());
}


Expand Down

0 comments on commit d5e7549

Please sign in to comment.