add more to the server response

This commit is contained in:
Lee
2024-04-10 09:19:02 +01:00
parent c7fe26ef8f
commit 330c3efc78
12 changed files with 540 additions and 19 deletions

@ -0,0 +1,30 @@
package cc.fascinated.common;
import lombok.experimental.UtilityClass;
@UtilityClass
public class ServerUtils {
/**
* Get the hostname and port from a hostname string
*
* @param hostname the hostname string
* @return the hostname and port
*/
public static Tuple<String, Integer> getHostnameAndPort(String hostname) {
String[] split = hostname.split(":");
if (split.length == 1) {
return new Tuple<>(split[0], 25565);
}
return new Tuple<>(split[0], Integer.parseInt(split[1]));
}
/**
* Gets the address of the server.
*
* @return the address of the server
*/
public static String getAddress(String ip, int port) {
return ip + (port == 25565 ? "" : ":" + port);
}
}