Skip to content

Commit 17dc22e

Browse files
authored
Possible fix for #326 (#363)
1 parent 2843a8e commit 17dc22e

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/main/java/world/bentobox/challenges/managers/ChallengesManager.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,36 @@ public class ChallengesManager
113113
* This comparator orders challenges by their level, order and name.
114114
*/
115115
private final Comparator<Challenge> challengeComparator = (o1, o2) -> {
116+
// Get the levels
116117
ChallengeLevel o1Level = this.getLevel(o1.getLevel());
117118
ChallengeLevel o2Level = this.getLevel(o2.getLevel());
118119

119-
if (o1Level == null && o2Level == null)
120-
{
120+
// Handle null levels consistently
121+
if (o1Level == null && o2Level == null) {
122+
// Both levels are null, compare by order
121123
return Integer.compare(o1.getOrder(), o2.getOrder());
122-
}
123-
else if (o1Level == null)
124-
{
124+
} else if (o1Level == null) {
125+
// If o1 level is null, it should be ordered lower
125126
return -1;
126-
}
127-
else if (o2Level == null)
128-
{
127+
} else if (o2Level == null) {
128+
// If o2 level is null, it should be ordered lower
129129
return 1;
130130
}
131-
else if (o1Level.equals(o2Level))
132-
{
131+
132+
// If both levels are non-null, compare their orders
133+
int levelComparison = Integer.compare(o1Level.getOrder(), o2Level.getOrder());
134+
135+
// If levels are the same, compare by challenge order
136+
if (levelComparison == 0) {
133137
return Integer.compare(o1.getOrder(), o2.getOrder());
134138
}
135-
else
136-
{
137-
return Integer.compare(o1Level.getOrder(), o2Level.getOrder());
138-
}
139+
140+
// Return the level comparison result
141+
return levelComparison;
139142
};
140143

141144

145+
142146
// ---------------------------------------------------------------------
143147
// Section: Constructor
144148
// ---------------------------------------------------------------------

0 commit comments

Comments
 (0)