Skip to content

Commit 009b53f

Browse files
authored
Fix tablist order for friends and nicked players (#1124)
Signed-off-by: applenick <applenick@users.noreply.github.com>
1 parent fa6d8bd commit 009b53f

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

core/src/main/java/tc/oc/pgm/tablist/PlayerOrder.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tc.oc.pgm.api.Config;
77
import tc.oc.pgm.api.PGM;
88
import tc.oc.pgm.api.Permissions;
9+
import tc.oc.pgm.api.integration.Integration;
910
import tc.oc.pgm.api.player.MatchPlayer;
1011

1112
/**
@@ -36,15 +37,28 @@ public int compare(MatchPlayer ma, MatchPlayer mb) {
3637
Player b = mb.getBukkit();
3738
Player viewer = this.viewer.getBukkit();
3839

39-
boolean aStaff = a.hasPermission(Permissions.STAFF);
40-
boolean bStaff = b.hasPermission(Permissions.STAFF);
40+
// Check if the viewer has staff permissions
41+
boolean isStaff = viewer.hasPermission(Permissions.STAFF);
4142

42-
// Staff take priority
43-
if (aStaff && !bStaff) {
44-
return -1;
45-
} else if (bStaff && !aStaff) {
46-
return 1;
47-
}
43+
// Check if viewer is friends with the player
44+
boolean aFriend = Integration.isFriend(viewer, a);
45+
boolean bFriend = Integration.isFriend(viewer, b);
46+
47+
if (aFriend && !bFriend) return -1;
48+
else if (bFriend && !aFriend) return 1;
49+
50+
String aNick = aFriend || isStaff ? null : Integration.getNick(a);
51+
String bNick = bFriend || isStaff ? null : Integration.getNick(b);
52+
53+
// Check if 'a' and 'b' are staff members (only counts if they're not nicked)
54+
boolean aStaff = aNick == null && a.hasPermission(Permissions.STAFF);
55+
boolean bStaff = bNick == null && b.hasPermission(Permissions.STAFF);
56+
57+
if (aStaff && !bStaff) return -1;
58+
else if (bStaff && !aStaff) return 1;
59+
60+
// Compare the nicknames of 'a' and 'b' if both are nicked, skip group permission check
61+
if (aNick != null && bNick != null) return aNick.compareToIgnoreCase(bNick);
4862

4963
// If players have different permissions, the player with the highest ranked perm
5064
// that the other one does't have is first. Disguised players effectively have no perms.

0 commit comments

Comments
 (0)