Skip to content

Commit

Permalink
Fix nicked player sorting in player list
Browse files Browse the repository at this point in the history
Signed-off-by: zzuf <[email protected]>
  • Loading branch information
zzufx committed Jan 3, 2024
1 parent 682f968 commit 21ec636
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/tc/oc/pgm/tablist/PlayerOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,26 @@ public int compare(MatchPlayer ma, MatchPlayer mb) {
if (aStaff && !bStaff) return -1;
else if (bStaff && !aStaff) return 1;

// Compare the nicknames of 'a' and 'b' if both are nicked, skip group permission check
// Compare the nicknames of 'a' and 'b'. If both are nicked, skip group permission check
if (aNick != null && bNick != null) return aNick.compareToIgnoreCase(bNick);

// If players have different permissions, the player with the highest ranked perm
// that the other one does't have is first. Disguised players effectively have no perms.
// that the other one doesn't have is first. Disguised players effectively have no perms.
for (Config.Group group : PGM.get().getConfiguration().getGroups()) {
Permission permission = group.getPermission();
boolean aPerm = a.hasPermission(permission);
boolean bPerm = b.hasPermission(permission);

if (aPerm && !bPerm) {
if (aPerm && (!bPerm && aNick == null)) {
return -1;
} else if (bPerm && !aPerm) {
} else if (bPerm && (!aPerm && bNick == null)) {
return 1;
}
}

if (aNick != null && bNick == null) return aNick.compareToIgnoreCase(b.getName());
else if (aNick == null && bNick != null) return a.getName().compareToIgnoreCase(bNick);

// All else equal, order the players alphabetically
return a.getName().compareToIgnoreCase(b.getName());
}
Expand Down

0 comments on commit 21ec636

Please sign in to comment.