31 lines
789 B
Java
31 lines
789 B
Java
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);
|
|
}
|
|
}
|