Reduce grouped packet buffer overhead

This commit is contained in:
TheMode 2021-05-10 11:16:17 +02:00
parent 10224baa96
commit d41a4dcf54

View File

@ -84,7 +84,6 @@ public final class PacketUtils {
// work out if the packet needs to be sent individually due to server-side translating
boolean needsTranslating = false;
if (AdventureSerializer.AUTOMATIC_COMPONENT_TRANSLATION && packet instanceof ComponentHoldingServerPacket) {
needsTranslating = AdventureSerializer.areAnyTranslatable(((ComponentHoldingServerPacket) packet).components());
}
@ -98,16 +97,12 @@ public final class PacketUtils {
// Send packet to all players
for (Player player : players) {
if (!player.isOnline())
continue;
// Verify if the player should receive the packet
if (playerValidator != null && !playerValidator.isValid(player))
continue;
finalBuffer.retain();
final PlayerConnection playerConnection = player.getPlayerConnection();
if (playerConnection instanceof NettyPlayerConnection) {
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
@ -115,15 +110,12 @@ public final class PacketUtils {
} else {
playerConnection.sendPacket(packet);
}
finalBuffer.release();
}
finalBuffer.release(); // Release last reference
}
} else {
// Write the same packet for each individual players
for (Player player : players) {
// Verify if the player should receive the packet
if (playerValidator != null && !playerValidator.isValid(player))
continue;