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 4, 2024
1 parent 682f968 commit d4286fd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/main/java/tc/oc/pgm/tablist/PlayerOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ 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()) {
if (group.getId().equalsIgnoreCase("default")) continue;

Permission permission = group.getPermission();
boolean aPerm = a.hasPermission(permission);
boolean bPerm = b.hasPermission(permission);
boolean aPerm = a.hasPermission(permission) && aNick == null;
boolean bPerm = b.hasPermission(permission) && bNick == null;

if (aPerm && !bPerm) {
return -1;
Expand All @@ -82,6 +84,7 @@ public int compare(MatchPlayer ma, MatchPlayer mb) {
}

// All else equal, order the players alphabetically
return a.getName().compareToIgnoreCase(b.getName());
return (aNick == null ? a.getName() : aNick)
.compareToIgnoreCase(bNick == null ? b.getName() : bNick);
}
}

0 comments on commit d4286fd

Please sign in to comment.