mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-25 20:15:27 +01:00
Add better challenge sorting in AdminGUI's
Now challenges will be sorted by their level order number, their order number, their unique id. All free challenges will always be at the start.
This commit is contained in:
parent
f2a4ab5817
commit
40e34e7999
@ -94,6 +94,45 @@ public class ChallengesManager
|
||||
public static final String FREE = "";
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Comparators
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This comparator orders challenges by their level, order and name.
|
||||
*/
|
||||
private final Comparator<Challenge> challengeComparator = (o1, o2) -> {
|
||||
if (o1.getLevel().equals(o2.getLevel()))
|
||||
{
|
||||
if (o1.getOrder() == o2.getOrder())
|
||||
{
|
||||
// If orders are equal, sort by unique Id
|
||||
return o1.getUniqueId().compareToIgnoreCase(o2.getUniqueId());
|
||||
}
|
||||
else
|
||||
{
|
||||
// If levels are equal, sort them by order numbers.
|
||||
return Integer.compare(o1.getOrder(), o2.getOrder());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (o1.getLevel().isEmpty() || o2.getLevel().isEmpty())
|
||||
{
|
||||
// If exist free level challenge, then it should be at the start.
|
||||
return Boolean.compare(o2.getLevel().isEmpty(), o1.getLevel().isEmpty());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sort by challenges level order numbers
|
||||
return Integer.compare(this.getLevel(o1.getLevel()).getOrder(),
|
||||
this.getLevel(o2.getLevel()).getOrder());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Constructor
|
||||
// ---------------------------------------------------------------------
|
||||
@ -1385,7 +1424,7 @@ public class ChallengesManager
|
||||
{
|
||||
return this.islandWorldManager.getAddon(world).map(gameMode ->
|
||||
this.challengeCacheData.values().stream().
|
||||
sorted(Comparator.comparing(Challenge::getOrder)).
|
||||
sorted(this.challengeComparator).
|
||||
filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
|
||||
map(Challenge::getUniqueId).
|
||||
collect(Collectors.toList())).
|
||||
@ -1403,7 +1442,7 @@ public class ChallengesManager
|
||||
{
|
||||
return this.islandWorldManager.getAddon(world).map(gameMode ->
|
||||
this.challengeCacheData.values().stream().
|
||||
sorted(Comparator.comparing(Challenge::getOrder)).
|
||||
sorted(this.challengeComparator).
|
||||
filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
|
||||
collect(Collectors.toList())).
|
||||
orElse(Collections.emptyList());
|
||||
|
Loading…
Reference in New Issue
Block a user