/*
 * The MIT License
 *
 * Copyright 2017 Fernando van Loenhout.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package me.ferrybig.javacoding.teamspeakconnector.internal;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.concurrent.Promise;
import me.ferrybig.javacoding.teamspeakconnector.TeamspeakConnection;
import me.ferrybig.javacoding.teamspeakconnector.internal.handler.ComplexPacketDecoder;
import me.ferrybig.javacoding.teamspeakconnector.internal.handler.HandshakeListener;
import me.ferrybig.javacoding.teamspeakconnector.internal.handler.PacketDecoder;
import me.ferrybig.javacoding.teamspeakconnector.internal.handler.PacketEncoder;
import me.ferrybig.javacoding.teamspeakconnector.internal.handler.PacketRateLimitingHandler;

public class TeamspeakConnectionInitizer extends ChannelInitializer<SocketChannel> {

	private static final StringDecoder DECODER = new StringDecoder();
	private static final StringEncoder ENCODER = new StringEncoder();
	private static final PacketDecoder PACKET_DECODER = new PacketDecoder();
	private static final PacketEncoder PACKET_ENCODER = new PacketEncoder();
	private static final ByteBuf[] LINES = new ByteBuf[]{
		Unpooled.wrappedBuffer(new byte[]{'\r', '\n'}), // I hate you teamspeak, Why do you use this format??
		Unpooled.wrappedBuffer(new byte[]{'\n', '\r'}),
		Unpooled.wrappedBuffer(new byte[]{'\n'}),};
	private final Promise<TeamspeakConnection> prom;
	private final int timeout;

	public TeamspeakConnectionInitizer(Promise<TeamspeakConnection> prom, int timeout) {
		this.prom = prom;
		this.timeout = timeout;
	}

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		pipeline.addLast(new DelimiterBasedFrameDecoder(Short.MAX_VALUE, LINES));
		pipeline.addLast(DECODER);
		pipeline.addLast(ENCODER);
		pipeline.addLast(new ReadTimeoutHandler(timeout));
		pipeline.addLast(new HandshakeListener(prom));

		pipeline.addLast(PACKET_DECODER);
		pipeline.addLast(new ComplexPacketDecoder());
		pipeline.addLast(PACKET_ENCODER);

		pipeline.addLast(new LoggingHandler(LogLevel.INFO));

		pipeline.addLast(new PacketRateLimitingHandler());
	}

}

@@ -1299,21 +1299,10 @@
 nnel
-Initializer
 ;%0A
+
 impo
@@ -1342,54 +1342,8 @@
 ne;%0A
-import io.netty.channel.socket.SocketChannel;%0A
 impo
@@ -1683,16 +1683,52 @@
 romise;%0A
+import java.util.function.Consumer;%0A
 import m
@@ -2263,41 +2263,28 @@
 zer 
-extends ChannelInitializer%3CSocket
+implements Consumer%3C
 Chan
@@ -3060,68 +3060,37 @@
 e%0A%09p
-rotected void initChannel(SocketChannel ch) throws Exception
+ublic void accept(Channel ch)
  %7B%0A%09

Use consumer