Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting indices of a list with children #6897

Merged
merged 9 commits into from
Jul 27, 2024
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/expressions/ExprIndices.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected String[] get(Event e) {
if (sort) {
int direction = descending ? -1 : 1;
return variable.entrySet().stream()
.peek((entry) -> entry.setValue(entry.getValue() instanceof Map<?,?> ? ((Map<?, ?>) entry.getValue()).get(null) : entry.getValue()))
potarodev marked this conversation as resolved.
Show resolved Hide resolved
.sorted((a, b) -> ExprSortedList.compare(a.getValue(), b.getValue()) * direction)
.map(Entry::getKey)
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
.toArray(String[]::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "sorted indices on map":
set {_test::1} to 111
set {_test::2} to 555
set {_test::3} to 444
set {_test::1::a} to 2
set {_test::2::b} to 3
set {_test::3::c} to 6
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
set {_indices::*} to (sorted indices of {_test::*} in ascending order)
assert {_indices::*} is ("1", "3", "2") with "sorted indices on list with children threw or was incorrect"