Files
Backend/src/main/java/xyz/mcutils/backend/model/server/MinecraftServer.java

153 lines
3.5 KiB
Java
Raw Normal View History

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 16:21:07 +01:00
import cc.fascinated.model.dns.DNSRecord;
2024-04-13 20:44:05 +01:00
import xyz.mcutils.backend.service.pinger.MinecraftServerPinger;
import xyz.mcutils.backend.service.pinger.impl.BedrockMinecraftServerPinger;
import xyz.mcutils.backend.service.pinger.impl.JavaMinecraftServerPinger;
2024-04-10 07:43:38 +01:00
import io.micrometer.common.lang.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
2024-04-10 16:21:07 +01:00
import lombok.Setter;
2024-04-10 07:43:38 +01:00
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
*/
2024-04-10 16:21:07 +01:00
@AllArgsConstructor
@Getter @Setter
2024-04-10 07:43:38 +01:00
public class MinecraftServer {
2024-04-10 16:21:07 +01:00
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
2024-04-10 16:21:07 +01:00
/**
* The DNS records for the server.
*/
private final DNSRecord[] records;
2024-04-10 16:21:07 +01:00
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.
*/
2024-04-10 16:21:07 +01:00
private final Players players;
2024-04-10 11:55:58 +01:00
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.
*/
@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
}