Fix LevelListRequestHandler.

This handler did not return list of strings but list of challenge levels, that is incorrect.
Not it should work correctly.
This commit is contained in:
BONNe 2019-11-13 16:16:59 +02:00 committed by BONNe1704
parent e75d13666e
commit 4cae1ed267
2 changed files with 29 additions and 11 deletions

View File

@ -1528,12 +1528,12 @@ public class ChallengesManager
public List<String> getAllChallengesNames(@NonNull World world) public List<String> getAllChallengesNames(@NonNull World world)
{ {
return this.islandWorldManager.getAddon(world).map(gameMode -> return this.islandWorldManager.getAddon(world).map(gameMode ->
this.challengeCacheData.values().stream(). this.challengeCacheData.values().stream().
filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())). filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
sorted(this.challengeComparator). sorted(this.challengeComparator).
map(Challenge::getUniqueId). map(Challenge::getUniqueId).
collect(Collectors.toList())). collect(Collectors.toList())).
orElse(Collections.emptyList()); orElse(Collections.emptyList());
} }
@ -1705,8 +1705,8 @@ public class ChallengesManager
public List<ChallengeLevel> getLevels(@NonNull World world) public List<ChallengeLevel> getLevels(@NonNull World world)
{ {
return this.islandWorldManager.getAddon(world).map(gameMode -> return this.islandWorldManager.getAddon(world).map(gameMode ->
this.getLevels(gameMode.getDescription().getName())). this.getLevels(gameMode.getDescription().getName())).
orElse(Collections.emptyList()); orElse(Collections.emptyList());
} }
@ -1719,9 +1719,26 @@ public class ChallengesManager
{ {
// TODO: Probably need to check also database. // TODO: Probably need to check also database.
return this.levelCacheData.values().stream(). 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). sorted(ChallengeLevel::compareTo).
filter(level -> level.matchGameMode(gameMode)). filter(level -> level.matchGameMode(gameMode.getDescription().getName())).
collect(Collectors.toList()); map(ChallengeLevel::getUniqueId).
collect(Collectors.toList())).
orElse(Collections.emptyList());
} }

View File

@ -52,7 +52,8 @@ public class LevelListRequestHandler extends AddonRequestHandler
return Collections.emptyList(); 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")));
} }