heap buffers don't need to be released manually

This commit is contained in:
Felix Cravic 2020-12-08 09:49:29 +01:00
parent b307a979c3
commit 91a000ab31

View File

@ -48,20 +48,14 @@ public final class PacketUtils {
final ByteBuf finalBuffer = createFramedPacket(packet, false);
final FramedPacket framedPacket = new FramedPacket(finalBuffer);
// Prevent premature release
final int refIncrease = players.size() - 1;
if (refIncrease > 0)
finalBuffer.retain(refIncrease);
// Send packet to all players
for (Player player : players) {
final PlayerConnection playerConnection = player.getPlayerConnection();
if (playerConnection instanceof NettyPlayerConnection) {
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
nettyPlayerConnection.write(framedPacket).addListener((p) -> finalBuffer.release());
nettyPlayerConnection.write(framedPacket);
} else {
playerConnection.sendPacket(packet);
finalBuffer.release();
}
}
}