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

122 lines
3.4 KiB
Java
Raw Normal View History

2024-04-10 11:55:58 +01:00
package cc.fascinated.model.server;
2024-04-10 16:21:07 +01:00
import cc.fascinated.model.dns.DNSRecord;
2024-04-10 11:55:58 +01:00
import lombok.*;
/**
* A Bedrock edition {@link MinecraftServer}.
*
* @author Braydon
*/
@Getter @ToString(callSuper = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public final class BedrockMinecraftServer extends MinecraftServer {
/**
* The unique ID of this server.
*/
2024-04-10 16:21:07 +01:00
@EqualsAndHashCode.Include @NonNull private final String id;
2024-04-10 11:55:58 +01:00
/**
* The edition of this server.
*/
@NonNull private final Edition edition;
/**
* The version information of this server.
*/
@NonNull private final Version version;
/**
* The gamemode of this server.
*/
@NonNull private final GameMode gamemode;
2024-04-10 16:21:07 +01:00
private BedrockMinecraftServer(@NonNull String id, @NonNull String hostname, String ip, int port, @NonNull DNSRecord[] records,
@NonNull Edition edition, @NonNull Version version, @NonNull Players players, @NonNull MOTD motd,
@NonNull GameMode gamemode) {
super(hostname, ip, port, records, motd, players);
this.id = id;
2024-04-10 11:55:58 +01:00
this.edition = edition;
this.version = version;
this.gamemode = gamemode;
}
/**
* Create a new Bedrock Minecraft server.
*
* @param hostname the hostname of the server
* @param ip the IP address of the server
* @param port the port of the server
* @param token the status token
* @return the Bedrock Minecraft server
*/
@NonNull
2024-04-10 16:21:07 +01:00
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @NonNull String token) {
2024-04-10 11:55:58 +01:00
String[] split = token.split(";"); // Split the token
Edition edition = Edition.valueOf(split[0]);
Version version = new Version(Integer.parseInt(split[2]), split[3]);
Players players = new Players(Integer.parseInt(split[4]), Integer.parseInt(split[5]), null);
MOTD motd = MOTD.create(split[1] + "\n" + split[7]);
GameMode gameMode = new GameMode(split[8], Integer.parseInt(split[9]));
2024-04-10 16:21:07 +01:00
return new BedrockMinecraftServer(
split[6],
hostname,
ip,
port,
records,
edition,
version,
players,
motd,
gameMode
);
2024-04-10 11:55:58 +01:00
}
/**
* The edition of a Bedrock server.
*/
@AllArgsConstructor @Getter
public enum Edition {
/**
* Minecraft: Pocket Edition.
*/
MCPE,
/**
* Minecraft: Education Edition.
*/
MCEE
}
/**
* Version information for a server.
*/
@AllArgsConstructor @Getter @ToString
public static class Version {
/**
* The protocol version of the server.
*/
private final int protocol;
/**
* The version name of the server.
*/
@NonNull private final String name;
}
/**
* The gamemode of a server.
*/
@AllArgsConstructor @Getter @ToString
public static class GameMode {
/**
* The name of this gamemode.
*/
@NonNull private final String name;
/**
* The numeric of this gamemode.
*/
private final int numericId;
}
}