6868import com .velocitypowered .proxy .protocol .packet .UpsertPlayerInfoPacket ;
6969import com .velocitypowered .proxy .protocol .packet .chat .ComponentHolder ;
7070import com .velocitypowered .proxy .protocol .packet .config .StartUpdatePacket ;
71+ import com .velocitypowered .proxy .protocol .util .DeferredByteBufHolder ;
7172import com .velocitypowered .proxy .protocol .util .PluginMessageUtil ;
7273import io .netty .buffer .ByteBuf ;
7374import io .netty .buffer .ByteBufUtil ;
@@ -91,6 +92,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
9192 Boolean .getBoolean ("velocity.log-server-backpressure" );
9293 private static final int MAXIMUM_PACKETS_TO_FLUSH =
9394 Integer .getInteger ("velocity.max-packets-per-flush" , 8192 );
95+ private static final int LARGE_PACKET_THRESHOLD = 1024 * 128 ;
9496
9597 private final VelocityServer server ;
9698 private final VelocityServerConnection serverConn ;
@@ -455,17 +457,19 @@ public void handleGeneric(MinecraftPacket packet) {
455457 if (packet instanceof PluginMessagePacket pluginMessage ) {
456458 pluginMessage .retain ();
457459 }
460+ boolean huge = packet instanceof DeferredByteBufHolder def && def .content ().readableBytes () > LARGE_PACKET_THRESHOLD ;
458461 playerConnection .delayedWrite (packet );
459- if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH ) {
462+ if (huge || ++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH ) {
460463 playerConnection .flush ();
461464 packetsFlushed = 0 ;
462465 }
463466 }
464467
465468 @ Override
466469 public void handleUnknown (ByteBuf buf ) {
470+ boolean huge = buf .readableBytes () > LARGE_PACKET_THRESHOLD ;
467471 playerConnection .delayedWrite (buf .retain ());
468- if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH ) {
472+ if (huge || ++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH ) {
469473 playerConnection .flush ();
470474 packetsFlushed = 0 ;
471475 }
0 commit comments