Fix primary groups being selected in reverse order

This commit is contained in:
Luck 2017-03-17 23:00:37 +00:00
parent 2e75bc3f3b
commit c2165e0196
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 4 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.common.utils.ExtractedContexts;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional; import java.util.Optional;
@ -53,7 +54,7 @@ public class AllParentsByWeightHolder extends StoredHolder {
.map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName()))) .map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName())))
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0))) .sorted(Collections.reverseOrder(Comparator.comparingInt(o -> o.getWeight().orElse(0))))
.findFirst() .findFirst()
.map(Group::getName) .map(Group::getName)
.orElse(null); .orElse(null);

View File

@ -26,6 +26,7 @@ import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional; import java.util.Optional;
@ -51,7 +52,7 @@ public class ParentsByWeightHolder extends StoredHolder {
.map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName()))) .map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName())))
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0))) .sorted(Collections.reverseOrder(Comparator.comparingInt(o -> o.getWeight().orElse(0))))
.findFirst() .findFirst()
.map(Group::getName) .map(Group::getName)
.orElse(null); .orElse(null);