From 69b476fcbcec5ecf3404a209232c4403647eaec4 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Fri, 26 Sep 2025 02:08:31 +0200 Subject: [PATCH] #3881: Optimize ServerUnique Tablist code Reduce amount of loops by pre checking values and not checking inside the loop --- .../net/md_5/bungee/tab/ServerUnique.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java index f70d357a..29ae9e46 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java @@ -22,12 +22,17 @@ public class ServerUnique extends TabList @Override public void onUpdate(PlayerListItem playerListItem) { - for ( PlayerListItem.Item item : playerListItem.getItems() ) + PlayerListItem.Action action = playerListItem.getAction(); + + if ( action == PlayerListItem.Action.ADD_PLAYER ) { - if ( playerListItem.getAction() == PlayerListItem.Action.ADD_PLAYER ) + for ( PlayerListItem.Item item : playerListItem.getItems() ) { uuids.add( item.getUuid() ); - } else if ( playerListItem.getAction() == PlayerListItem.Action.REMOVE_PLAYER ) + } + } else if ( action == PlayerListItem.Action.REMOVE_PLAYER ) + { + for ( PlayerListItem.Item item : playerListItem.getItems() ) { uuids.remove( item.getUuid() ); } @@ -48,14 +53,11 @@ public class ServerUnique extends TabList @Override public void onUpdate(PlayerListItemUpdate playerListItem) { - for ( PlayerListItem.Item item : playerListItem.getItems() ) + if ( playerListItem.getActions().contains( PlayerListItemUpdate.Action.ADD_PLAYER ) ) { - for ( PlayerListItemUpdate.Action action : playerListItem.getActions() ) + for ( PlayerListItem.Item item : playerListItem.getItems() ) { - if ( action == PlayerListItemUpdate.Action.ADD_PLAYER ) - { - uuids.add( item.getUuid() ); - } + uuids.add( item.getUuid() ); } } player.unsafe().sendPacket( playerListItem ); @@ -73,7 +75,7 @@ public class ServerUnique extends TabList if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_19_3 ) { PlayerListItemRemove packet = new PlayerListItemRemove(); - packet.setUuids( uuids.stream().toArray( UUID[]::new ) ); + packet.setUuids( uuids.toArray( new UUID[ 0 ] ) ); player.unsafe().sendPacket( packet ); } else {