Added missing Methods
This commit is contained in:
@@ -269,6 +269,36 @@ public class NetworkClient {
|
||||
udpPort = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the TCP connection is established
|
||||
*/
|
||||
public boolean isTCPConnected() {
|
||||
return tcpSocket != null && tcpSocket.isConnected() && !tcpSocket.isClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the UDP connection is established
|
||||
*/
|
||||
public boolean isUDPConnected() {
|
||||
return isUDPEnabled() && udpChannel != null && udpChannel.isConnected() && udpChannel.isOpen();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if TCP is connected and (if enabled) UDP is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
if (!isTCPConnected()) return false;
|
||||
if (isUDPEnabled()) return isUDPConnected();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if UDP is enabled for this client
|
||||
*/
|
||||
public boolean isUDPEnabled() {
|
||||
return udpPort != -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builder for {@link NetworkClient}.
|
||||
|
||||
@@ -154,6 +154,11 @@ public class ConnectedClient {
|
||||
return isUDPEnabled() && isTCPConnected() && udpChannel != null && udpChannel.isOpen();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
if (!isTCPConnected()) return false;
|
||||
return isUDPEnabled() && isUDPConnected();
|
||||
}
|
||||
|
||||
public UUID getUniqueID() {
|
||||
return uniqueID;
|
||||
}
|
||||
|
||||
@@ -246,6 +246,21 @@ public class NetworkServer {
|
||||
return udpPort != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the server is currently online.
|
||||
* If UDP is enabled, the UDP channel must be open as well.
|
||||
*
|
||||
* @return true if TCP is open and (if enabled) UDP is open
|
||||
*/
|
||||
public boolean isServerOnline() {
|
||||
boolean tcpOnline = tcpSocket != null && !tcpSocket.isClosed() && tcpSocket.isBound();
|
||||
if (!tcpOnline) return false;
|
||||
if (isUDPEnabled()) {
|
||||
return udpChannel != null && udpChannel.isOpen();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return packet handler
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user