Make ProxyPingEvent async

This commit is contained in:
Steve Anton
2014-09-05 20:23:01 -07:00
committed by md_5
parent 65ae8b4c6a
commit bc48ab3fb8
2 changed files with 45 additions and 16 deletions

View File

@@ -134,17 +134,32 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
ServerPing legacy = new ServerPing( new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), bungee.getProtocolVersion() ),
new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), listener.getMotd(), (Favicon) null );
legacy = bungee.getPluginManager().callEvent( new ProxyPingEvent( this, legacy ) ).getResponse();
String kickMessage = ChatColor.DARK_BLUE
+ "\00" + 127
+ "\00" + legacy.getVersion().getName()
+ "\00" + legacy.getDescription()
+ "\00" + legacy.getPlayers().getOnline()
+ "\00" + legacy.getPlayers().getMax();
Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
{
@Override
public void done(ProxyPingEvent result, Throwable error)
{
if ( ch.isClosed() )
{
return;
}
ch.getHandle().writeAndFlush( kickMessage );
ch.close();
ServerPing ping = result.getResponse();
String kickMessage = ChatColor.DARK_BLUE
+ "\00" + 127
+ "\00" + ping.getVersion().getName()
+ "\00" + ping.getDescription()
+ "\00" + ping.getPlayers().getOnline()
+ "\00" + ping.getPlayers().getMax();
ch.getHandle().writeAndFlush( kickMessage );
ch.close();
}
};
bungee.getPluginManager().callEvent( new ProxyPingEvent( this, legacy, callback ) );
}
@Override
@@ -166,11 +181,19 @@ public class InitialHandler extends PacketHandler implements PendingConnection
result.setDescription( bungee.getTranslation( "ping_cannot_connect" ) );
bungee.getLogger().log( Level.WARNING, "Error pinging remote server", error );
}
result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse();
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson;
unsafe.sendPacket( new StatusResponse( gson.toJson( result ) ) );
Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
{
@Override
public void done(ProxyPingEvent pingResult, Throwable error)
{
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson;
unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) );
}
};
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, callback ) );
}
};