Sort users with no known username to the bottom of the editor menu

This commit is contained in:
Luck 2020-11-10 15:04:36 +00:00
parent 93d0c54687
commit 4ce8ea21f9
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -57,7 +57,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class EditorCommand extends SingleCommand { public class EditorCommand extends SingleCommand {
public static final int MAX_USERS = 1000; public static final int MAX_USERS = 500;
public EditorCommand() { public EditorCommand() {
super(CommandSpec.EDITOR, "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 2)); super(CommandSpec.EDITOR, "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 2));
@ -145,7 +145,11 @@ public class EditorCommand extends SingleCommand {
users.values().stream() users.values().stream()
.sorted(Comparator .sorted(Comparator
// sort firstly by the users relative weight (depends on the groups they inherit)
.<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL)).reversed() .<User>comparingInt(u -> u.getCachedData().getMetaData(QueryOptions.nonContextual()).getWeight(MetaCheckEvent.Origin.INTERNAL)).reversed()
// then, prioritise users we actually have a username for
.thenComparing(u -> u.getUsername().isPresent(), ((Comparator<Boolean>) Boolean::compare).reversed())
// then sort according to their username
.thenComparing(User::getPlainDisplayName, String.CASE_INSENSITIVE_ORDER) .thenComparing(User::getPlainDisplayName, String.CASE_INSENSITIVE_ORDER)
) )
.forEach(holders::add); .forEach(holders::add);