Add Connection.isConnected()Z API.

Idea from kamcio96 in #1693
This commit is contained in:
md_5 2016-01-16 12:25:01 +11:00
parent 841c81cdc4
commit e556fd7150
4 changed files with 31 additions and 8 deletions

View File

@ -51,6 +51,14 @@ public interface Connection
*/ */
void disconnect(BaseComponent reason); void disconnect(BaseComponent reason);
/**
* Gets whether this connection is currently open, ie: not disconnected, and
* able to send / receive data.
*
* @return current connection status
*/
boolean isConnected();
/** /**
* Get the unsafe methods of this class. * Get the unsafe methods of this class.
* *

View File

@ -77,6 +77,12 @@ public class ServerConnection implements Server
return getInfo().getAddress(); return getInfo().getAddress();
} }
@Override
public boolean isConnected()
{
return !ch.isClosed();
}
@Override @Override
public Unsafe unsafe() public Unsafe unsafe()
{ {

View File

@ -274,15 +274,12 @@ public final class UserConnection implements ProxiedPlayer
{ {
sendMessage( bungee.getTranslation( "fallback_lobby" ) ); sendMessage( bungee.getTranslation( "fallback_lobby" ) );
connect( def, null, false ); connect( def, null, false );
} else if ( dimensionChange )
{
disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
} else } else
{ {
if ( dimensionChange ) sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
{
disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
} else
{
sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
}
} }
} }
} }
@ -592,4 +589,10 @@ public final class UserConnection implements ProxiedPlayer
ch.setCompressionThreshold( compressionThreshold ); ch.setCompressionThreshold( compressionThreshold );
} }
} }
@Override
public boolean isConnected()
{
return !ch.isClosed();
}
} }

View File

@ -74,7 +74,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private LoginRequest loginRequest; private LoginRequest loginRequest;
private EncryptionRequest request; private EncryptionRequest request;
@Getter @Getter
private final List<PluginMessage> registerMessages = new BoundedArrayList<>(128); private final List<PluginMessage> registerMessages = new BoundedArrayList<>( 128 );
private State thisState = State.HANDSHAKE; private State thisState = State.HANDSHAKE;
private final Unsafe unsafe = new Unsafe() private final Unsafe unsafe = new Unsafe()
{ {
@ -606,4 +606,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
return "[" + ( ( getName() != null ) ? getName() : getAddress() ) + "] <-> InitialHandler"; return "[" + ( ( getName() != null ) ? getName() : getAddress() ) + "] <-> InitialHandler";
} }
@Override
public boolean isConnected()
{
return !ch.isClosed();
}
} }