2626import net .minecraft .client .MinecraftClient ;
2727import net .minecraft .client .gui .hud .PlayerListHud ;
2828import net .minecraft .client .network .PlayerListEntry ;
29+ import net .minecraft .scoreboard .Team ;
2930import net .minecraft .text .MutableText ;
3031import net .minecraft .text .Text ;
32+ import net .minecraft .util .Nullables ;
33+ import net .minecraft .world .GameMode ;
3134import org .jetbrains .annotations .Nullable ;
3235import org .spongepowered .asm .mixin .Final ;
3336import org .spongepowered .asm .mixin .Mixin ;
4548@ Mixin (PlayerListHud .class )
4649public class PlayerListHudMixin {
4750 @ Shadow @ Final private static Comparator <PlayerListEntry > ENTRY_ORDERING ;
51+ @ Unique @ Final private static Comparator <PlayerListEntry > FRIENDS_FIRST_ENTRY_ORDERING = Comparator
52+ .comparingInt ((PlayerListEntry entry ) -> FriendManager .INSTANCE .isFriend (entry .getProfile ().name ()) ? 0 : 1 )
53+ .thenComparingInt (entry -> -entry .getListOrder ())
54+ .thenComparingInt ((entry ) -> entry .getGameMode () == GameMode .SPECTATOR ? 1 : 0 )
55+ .thenComparing ((entry ) -> Nullables .mapOrElse (entry .getScoreboardTeam (), Team ::getName , "" ))
56+ .thenComparing ((entry ) -> entry .getProfile ().name (), String ::compareToIgnoreCase );
4857
4958 @ Shadow @ Final private MinecraftClient client ;
5059
@@ -57,7 +66,7 @@ private void onCollectPlayerEntriesHead(CallbackInfoReturnable<List<PlayerListEn
5766 .getListedPlayerListEntries ()
5867 .stream ()
5968 .filter (entry -> !ExtraTab .getFriendsOnly () || FriendManager .INSTANCE .isFriend (entry .getProfile ()))
60- .sorted (ENTRY_ORDERING )
69+ .sorted (ExtraTab . getSortFriendsFirst () ? FRIENDS_FIRST_ENTRY_ORDERING : ENTRY_ORDERING )
6170 .limit (ExtraTab .getTabEntries ())
6271 .toList ()
6372 );
0 commit comments