Skip to content

Commit

Permalink
Fix LevelListRequestHandler.
Browse files Browse the repository at this point in the history
This handler did not return list of strings but list of challenge levels, that is incorrect.
Not it should work correctly.
  • Loading branch information
BONNe committed Nov 13, 2019
1 parent e75d136 commit 4cae1ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1528,12 +1528,12 @@ public List<LevelStatus> getAllChallengeLevelStatus(User user, World world)
public List<String> getAllChallengesNames(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
this.challengeCacheData.values().stream().
filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
sorted(this.challengeComparator).
map(Challenge::getUniqueId).
collect(Collectors.toList())).
orElse(Collections.emptyList());
this.challengeCacheData.values().stream().
filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
sorted(this.challengeComparator).
map(Challenge::getUniqueId).
collect(Collectors.toList())).
orElse(Collections.emptyList());
}


Expand Down Expand Up @@ -1705,8 +1705,8 @@ public void deleteChallenge(Challenge challenge)
public List<ChallengeLevel> getLevels(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
this.getLevels(gameMode.getDescription().getName())).
orElse(Collections.emptyList());
this.getLevels(gameMode.getDescription().getName())).
orElse(Collections.emptyList());
}


Expand All @@ -1719,9 +1719,26 @@ private List<ChallengeLevel> getLevels(String gameMode)
{
// TODO: Probably need to check also database.
return this.levelCacheData.values().stream().
sorted(ChallengeLevel::compareTo).
filter(level -> level.matchGameMode(gameMode)).
collect(Collectors.toList());
}


/**
* This method returns list of challenge levels in given gameMode.
* @param world for which levels must be searched.
* @return List with challengeLevel uniqueIds in given world.
*/
public List<String> getLevelNames(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
this.levelCacheData.values().stream().
sorted(ChallengeLevel::compareTo).
filter(level -> level.matchGameMode(gameMode)).
collect(Collectors.toList());
filter(level -> level.matchGameMode(gameMode.getDescription().getName())).
map(ChallengeLevel::getUniqueId).
collect(Collectors.toList())).
orElse(Collections.emptyList());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public Object handle(Map<String, Object> metaData)
return Collections.emptyList();
}

return this.addon.getChallengesManager().getLevels(Bukkit.getWorld((String) metaData.get("world-name")));
return this.addon.getChallengesManager().getLevelNames(
Bukkit.getWorld((String) metaData.get("world-name")));
}


Expand Down

0 comments on commit 4cae1ed

Please sign in to comment.