From 290e7f633bb2ecffad78a8a2518ea9efdf890767 Mon Sep 17 00:00:00 2001 From: foss-mc <69294560+foss-mc@users.noreply.github.com> Date: Wed, 16 Dec 2020 18:30:07 +0800 Subject: [PATCH] Use pipeline to reduce redundancy diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index 5c05f2b9..606866a5 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -5,6 +5,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; + import java.net.SocketAddress; import java.util.concurrent.TimeUnit; import lombok.Getter; @@ -37,14 +39,18 @@ public class ChannelWrapper public void setProtocol(Protocol protocol) { - ch.pipeline().get( MinecraftDecoder.class ).setProtocol( protocol ); - ch.pipeline().get( MinecraftEncoder.class ).setProtocol( protocol ); + // FlameCord - Use pipeline to reduce redundancy + final ChannelPipeline pipeline = ch.pipeline(); + pipeline.get( MinecraftDecoder.class ).setProtocol( protocol ); + pipeline.get( MinecraftEncoder.class ).setProtocol( protocol ); } public void setVersion(int protocol) { - ch.pipeline().get( MinecraftDecoder.class ).setProtocolVersion( protocol ); - ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol ); + // FlameCord - Use pipeline to reduce redundancy + final ChannelPipeline pipeline = ch.pipeline(); + pipeline.get( MinecraftDecoder.class ).setProtocolVersion( protocol ); + pipeline.get( MinecraftEncoder.class ).setProtocolVersion( protocol ); } public void write(Object packet) @@ -111,25 +117,27 @@ public class ChannelWrapper public void setCompressionThreshold(int compressionThreshold) { - if ( ch.pipeline().get( PacketCompressor.class ) == null && compressionThreshold != -1 ) + // FlameCord - Use pipeline to reduce redundancy + final ChannelPipeline pipeline = ch.pipeline(); + if ( pipeline.get( PacketCompressor.class ) == null && compressionThreshold != -1 ) { addBefore( PipelineUtils.PACKET_ENCODER, "compress", new PacketCompressor() ); } if ( compressionThreshold != -1 ) { - ch.pipeline().get( PacketCompressor.class ).setThreshold( compressionThreshold ); + pipeline.get( PacketCompressor.class ).setThreshold( compressionThreshold ); } else { - ch.pipeline().remove( "compress" ); + pipeline.remove( "compress" ); } - if ( ch.pipeline().get( PacketDecompressor.class ) == null && compressionThreshold != -1 ) + if ( pipeline.get( PacketDecompressor.class ) == null && compressionThreshold != -1 ) { addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor(compressionThreshold) ); } if ( compressionThreshold == -1 ) { - ch.pipeline().remove( "decompress" ); + pipeline.remove( "decompress" ); } } } -- 2.32.0