Skip to content

Commit

Permalink
SpigotMC#3769: Fix possible NoSuchElementException changing compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Outfluencer authored and md-5 committed Jan 7, 2025
1 parent d995702 commit 1265a99
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,32 @@ public Channel getHandle()

public void setCompressionThreshold(int compressionThreshold)
{
if ( ch.pipeline().get( PacketCompressor.class ) == null && compressionThreshold >= 0 )
{
addBefore( PipelineUtils.PACKET_ENCODER, "compress", new PacketCompressor() );
}
PacketCompressor compressor = ch.pipeline().get( PacketCompressor.class );
PacketDecompressor decompressor = ch.pipeline().get( PacketDecompressor.class );
if ( compressionThreshold >= 0 )
{
ch.pipeline().get( PacketCompressor.class ).setThreshold( compressionThreshold );
if ( compressor == null )
{
addBefore( PipelineUtils.PACKET_ENCODER, "compress", compressor = new PacketCompressor() );
}
compressor.setThreshold( compressionThreshold );

if ( decompressor == null )
{
addBefore( PipelineUtils.PACKET_DECODER, "decompress", decompressor = new PacketDecompressor() );
}
} else
{
ch.pipeline().remove( "compress" );
if ( compressor != null )
{
ch.pipeline().remove( "compress" );
}
if ( decompressor != null )
{
ch.pipeline().remove( "decompress" );
}
}

if ( ch.pipeline().get( PacketDecompressor.class ) == null && compressionThreshold >= 0 )
{
addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor() );
}
if ( compressionThreshold < 0 )
{
ch.pipeline().remove( "decompress" );
}
// disable use of composite buffers if we use natives
updateComposite();
}
Expand Down

0 comments on commit 1265a99

Please sign in to comment.