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);
/**
* 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.
*

View File

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

View File

@ -274,9 +274,7 @@ public final class UserConnection implements ProxiedPlayer
{
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
connect( def, null, false );
} else
{
if ( dimensionChange )
} else if ( dimensionChange )
{
disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
} else
@ -285,7 +283,6 @@ public final class UserConnection implements ProxiedPlayer
}
}
}
}
};
Bootstrap b = new Bootstrap()
.channel( PipelineUtils.getChannel() )
@ -592,4 +589,10 @@ public final class UserConnection implements ProxiedPlayer
ch.setCompressionThreshold( compressionThreshold );
}
}
@Override
public boolean isConnected()
{
return !ch.isClosed();
}
}

View File

@ -606,4 +606,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
return "[" + ( ( getName() != null ) ? getName() : getAddress() ) + "] <-> InitialHandler";
}
@Override
public boolean isConnected()
{
return !ch.isClosed();
}
}