2024-04-10 07:43:38 +01:00
|
|
|
package cc.fascinated.model.server;
|
|
|
|
|
2024-04-10 09:19:02 +01:00
|
|
|
import cc.fascinated.common.ColorUtils;
|
2024-04-10 07:43:38 +01:00
|
|
|
import cc.fascinated.service.pinger.MinecraftServerPinger;
|
2024-04-10 11:55:58 +01:00
|
|
|
import cc.fascinated.service.pinger.impl.BedrockMinecraftServerPinger;
|
2024-04-10 07:43:38 +01:00
|
|
|
import cc.fascinated.service.pinger.impl.JavaMinecraftServerPinger;
|
|
|
|
import io.micrometer.common.lang.NonNull;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.ToString;
|
|
|
|
|
2024-04-10 09:19:02 +01:00
|
|
|
import java.util.Arrays;
|
2024-04-10 11:55:58 +01:00
|
|
|
import java.util.UUID;
|
2024-04-10 09:19:02 +01:00
|
|
|
|
2024-04-10 07:43:38 +01:00
|
|
|
/**
|
|
|
|
* @author Braydon
|
|
|
|
*/
|
|
|
|
@AllArgsConstructor @Getter @ToString
|
|
|
|
public class MinecraftServer {
|
2024-04-10 11:55:58 +01:00
|
|
|
/**
|
|
|
|
* The hostname of the server.
|
|
|
|
*/
|
2024-04-10 07:43:38 +01:00
|
|
|
private final String hostname;
|
2024-04-10 11:55:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The IP address of the server.
|
|
|
|
*/
|
2024-04-10 07:43:38 +01:00
|
|
|
private final String ip;
|
2024-04-10 11:55:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The port of the server.
|
|
|
|
*/
|
2024-04-10 07:43:38 +01:00
|
|
|
private final int port;
|
2024-04-10 11:55:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The motd for the server.
|
|
|
|
*/
|
2024-04-10 09:19:02 +01:00
|
|
|
private final MOTD motd;
|
2024-04-10 07:43:38 +01:00
|
|
|
|
2024-04-10 11:55:58 +01:00
|
|
|
/**
|
|
|
|
* The players on the server.
|
|
|
|
*/
|
|
|
|
private Players players;
|
|
|
|
|
2024-04-10 07:43:38 +01:00
|
|
|
/**
|
|
|
|
* A platform a Minecraft
|
|
|
|
* server can operate on.
|
|
|
|
*/
|
|
|
|
@AllArgsConstructor @Getter
|
|
|
|
public enum Platform {
|
|
|
|
/**
|
|
|
|
* The Java edition of Minecraft.
|
|
|
|
*/
|
2024-04-10 11:55:58 +01:00
|
|
|
JAVA(new JavaMinecraftServerPinger(), 25565),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Bedrock edition of Minecraft.
|
|
|
|
*/
|
|
|
|
BEDROCK(new BedrockMinecraftServerPinger(), 19132);
|
2024-04-10 07:43:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The server pinger for this platform.
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
private final MinecraftServerPinger<?> pinger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default server port for this platform.
|
|
|
|
*/
|
|
|
|
private final int defaultPort;
|
|
|
|
}
|
2024-04-10 09:19:02 +01:00
|
|
|
|
|
|
|
@AllArgsConstructor @Getter
|
|
|
|
public static class MOTD {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The raw motd lines
|
|
|
|
*/
|
|
|
|
private final String[] raw;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The clean motd lines
|
|
|
|
*/
|
|
|
|
private final String[] clean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The html motd lines
|
|
|
|
*/
|
|
|
|
private final String[] html;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new MOTD from a raw string.
|
|
|
|
*
|
|
|
|
* @param raw the raw motd string
|
|
|
|
* @return the new motd
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
public static MOTD create(@NonNull String raw) {
|
|
|
|
String[] rawLines = raw.split("\n"); // The raw lines
|
|
|
|
return new MOTD(
|
|
|
|
rawLines,
|
|
|
|
Arrays.stream(rawLines).map(ColorUtils::stripColor).toArray(String[]::new),
|
|
|
|
Arrays.stream(rawLines).map(ColorUtils::toHTML).toArray(String[]::new)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-04-10 11:55:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Player count data for a server.
|
|
|
|
*/
|
2024-04-10 13:24:56 +01:00
|
|
|
@AllArgsConstructor @Getter
|
2024-04-10 11:55:58 +01:00
|
|
|
public static class Players {
|
|
|
|
/**
|
|
|
|
* The online players on this server.
|
|
|
|
*/
|
|
|
|
private final int online;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum allowed players on this server.
|
|
|
|
*/
|
|
|
|
private final int max;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A sample of players on this server, null or empty if no sample.
|
|
|
|
*/
|
|
|
|
private final Sample[] sample;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A sample player.
|
|
|
|
*/
|
|
|
|
@AllArgsConstructor @Getter @ToString
|
|
|
|
public static class Sample {
|
|
|
|
/**
|
|
|
|
* The unique id of this player.
|
|
|
|
*/
|
|
|
|
@NonNull private final UUID id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of this player.
|
|
|
|
*/
|
|
|
|
@NonNull private final String name;
|
|
|
|
}
|
|
|
|
}
|
2024-04-10 07:43:38 +01:00
|
|
|
}
|