From 617c19bf3c7053f3992360a3f863fc5085d28430 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sat, 6 Apr 2024 19:18:34 -0400 Subject: [PATCH] MC server models --- .../me/braydon/mc/model/MinecraftServer.java | 90 +++++++++++++++++++ .../model/server/BedrockMinecraftServer.java | 16 ++++ .../mc/model/server/JavaMinecraftServer.java | 20 +++++ 3 files changed, 126 insertions(+) create mode 100644 src/main/java/me/braydon/mc/model/MinecraftServer.java create mode 100644 src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java create mode 100644 src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java diff --git a/src/main/java/me/braydon/mc/model/MinecraftServer.java b/src/main/java/me/braydon/mc/model/MinecraftServer.java new file mode 100644 index 0000000..c6bfad5 --- /dev/null +++ b/src/main/java/me/braydon/mc/model/MinecraftServer.java @@ -0,0 +1,90 @@ +package me.braydon.mc.model; + +import lombok.*; +import me.braydon.mc.service.pinger.MinecraftServerPinger; +import me.braydon.mc.service.pinger.impl.BedrockMinecraftServerPinger; +import me.braydon.mc.service.pinger.impl.JavaMinecraftServerPinger; + +import java.beans.JavaBean; + +/** + * A model representing a Minecraft server. + * + * @author Braydon + */ +@AllArgsConstructor @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true) @ToString +public class MinecraftServer { + /** + * The IP address of this server. + */ + @EqualsAndHashCode.Include @NonNull private final String ip; + + /** + * The port of this server. + */ + @EqualsAndHashCode.Include private final int port; + + /** + * The version information of this server. + */ + @NonNull private final Version version; + + /** + * The player counts of this server. + */ + @NonNull private final Players players; + + /** + * Version information for a server. + */ + @AllArgsConstructor @Getter @ToString + public static class Version { + /** + * The version name of the server. + */ + @NonNull private final String name; + + /** + * The protocol version of the server. + */ + private final int protocol; + } + + /** + * Player count data for a server. + */ + @AllArgsConstructor @Getter @ToString + 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 platform a Minecraft + * server can operate on. + */ + @AllArgsConstructor @Getter + public enum Platform { + /** + * The Java edition of Minecraft. + */ + JAVA(new JavaMinecraftServerPinger()), + + /** + * The Bedrock edition of Minecraft. + */ + BEDROCK(new BedrockMinecraftServerPinger()); + + /** + * The server pinger for this platform. + */ + @NonNull private final MinecraftServerPinger pinger; + } +} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java b/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java new file mode 100644 index 0000000..ce32940 --- /dev/null +++ b/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java @@ -0,0 +1,16 @@ +package me.braydon.mc.model.server; + +import lombok.NonNull; +import me.braydon.mc.model.MinecraftServer; +import me.braydon.mc.model.token.JavaServerStatusToken; + +/** + * A Bedrock edition {@link MinecraftServer}. + * + * @author Braydon + */ +public final class BedrockMinecraftServer extends MinecraftServer { + private BedrockMinecraftServer(@NonNull String ip, int port, @NonNull Version version, @NonNull Players players) { + super(ip, port, version, players); + } +} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java b/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java new file mode 100644 index 0000000..f0dc699 --- /dev/null +++ b/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java @@ -0,0 +1,20 @@ +package me.braydon.mc.model.server; + +import lombok.NonNull; +import me.braydon.mc.model.MinecraftServer; +import me.braydon.mc.model.token.JavaServerStatusToken; + +/** + * A Java edition {@link MinecraftServer}. + * + * @author Braydon + */ +public final class JavaMinecraftServer extends MinecraftServer { + private JavaMinecraftServer(@NonNull String ip, int port, @NonNull Version version, @NonNull Players players) { + super(ip, port, version, players); + } + + public static JavaMinecraftServer create(@NonNull String ip, int port, @NonNull JavaServerStatusToken token) { + return new JavaMinecraftServer(ip, port, token.getVersion(), token.getPlayers()); + } +} \ No newline at end of file