src/main/java/cc.fascinated
common
controller
model
service
target/classes/templates
30
src/main/java/cc.fascinated/common/ServerUtils.java
Normal file
30
src/main/java/cc.fascinated/common/ServerUtils.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user