From c5e15697a499f8b9ad3442cca5754d1c5d79e423 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 10 Feb 2013 20:18:08 +1100 Subject: [PATCH] Fix server ping method. --- .../net/md_5/bungee/BungeeServerInfo.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 3711d5a0..00d38fd7 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -48,24 +48,21 @@ public class BungeeServerInfo extends ServerInfo @Override public void run() { - try + try ( Socket socket = new Socket(); ) { - Socket socket = new Socket(); socket.connect( getAddress() ); - try ( DataOutputStream out = new DataOutputStream( socket.getOutputStream() ) ) - { - out.write( 0xFE ); - out.write( 0x01 ); - } - try ( PacketStream in = new PacketStream( socket.getInputStream() ) ) - { - PacketFFKick response = new PacketFFKick( in.readPacket() ); - String[] split = response.message.split( "\00" ); + DataOutputStream out = new DataOutputStream( socket.getOutputStream() ); + out.write( 0xFE ); + out.write( 0x01 ); - ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); - callback.done( ping, null ); - } + PacketStream in = new PacketStream( socket.getInputStream() ); + PacketFFKick response = new PacketFFKick( in.readPacket() ); + + String[] split = response.message.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 ); } catch ( Throwable t ) { callback.done( null, t );