package net.md_5.bungee.connection;

import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.packet.PacketFFKick;

@RequiredArgsConstructor
public class PingHandler extends PacketHandler
{

    private final ServerInfo target;
    private final Callback<ServerPing> callback;
    private static final byte[] pingBuf = new byte[]
    {
        (byte) 0xFE, (byte) 0x01
    };

    @Override
    public void connected(ChannelWrapper channel) throws Exception
    {
        channel.write( pingBuf );
    }

    @Override
    public void exception(Throwable t) throws Exception
    {
        callback.done( null, t );
    }

    @Override
    public void handle(PacketFFKick kick) throws Exception
    {
        String[] split = kick.getMessage().split( "\00" );
        ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
        callback.done( ping, null );
    }

    @Override
    public String toString()
    {
        return "[Ping Handler] -> " + target.getName();
    }
}

@@ -30,16 +30,81 @@
 ction;%0A%0A
+import io.netty.buffer.ByteBuf;%0Aimport io.netty.buffer.Unpooled;%0A
 import l
@@ -560,16 +560,57 @@
 llback;%0A
+    // TODO: Update this to 1.6.2 style!%0A
     priv
@@ -626,22 +626,23 @@
 c final 
-byte%5B%5D
+ByteBuf
  pingBuf
@@ -643,16 +643,40 @@
 ingBuf =
+ Unpooled.wrappedBuffer(
  new byt
@@ -723,16 +723,18 @@
 01%0A    %7D
+ )
 ;%0A%0A    @

Write down a supported message type (ByteBuf) when using the ping handler.