Added missing Methods

This commit is contained in:
Finn
2026-02-01 15:58:47 +01:00
parent a93fa71f3d
commit e8961fc56a
4 changed files with 51 additions and 1 deletions

View File

@@ -6,7 +6,7 @@
<groupId>dev.unlegitdqrk</groupId> <groupId>dev.unlegitdqrk</groupId>
<artifactId>unlegitlibrary</artifactId> <artifactId>unlegitlibrary</artifactId>
<version>1.7.2</version> <version>1.7.4</version>
<url>https://unlegitdqrk.dev/</url> <url>https://unlegitdqrk.dev/</url>
<description>Just a big library</description> <description>Just a big library</description>

View File

@@ -269,6 +269,36 @@ public class NetworkClient {
udpPort = -1; 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}. * Builder for {@link NetworkClient}.

View File

@@ -154,6 +154,11 @@ public class ConnectedClient {
return isUDPEnabled() && isTCPConnected() && udpChannel != null && udpChannel.isOpen(); return isUDPEnabled() && isTCPConnected() && udpChannel != null && udpChannel.isOpen();
} }
public boolean isConnected() {
if (!isTCPConnected()) return false;
return isUDPEnabled() && isUDPConnected();
}
public UUID getUniqueID() { public UUID getUniqueID() {
return uniqueID; return uniqueID;
} }

View File

@@ -246,6 +246,21 @@ public class NetworkServer {
return udpPort != -1; 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 * @return packet handler
*/ */