From fbdd2fc9a7b4b6c4694af64bf3b20781a04da3ce Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sat, 6 Apr 2024 21:52:19 -0400 Subject: [PATCH] Add Forge ModInfo --- .../me/braydon/mc/model/MinecraftServer.java | 44 --------- .../model/server/BedrockMinecraftServer.java | 6 +- .../mc/model/server/JavaMinecraftServer.java | 96 +++++++++++++++++-- .../mc/model/token/JavaServerStatusToken.java | 9 +- 4 files changed, 101 insertions(+), 54 deletions(-) diff --git a/src/main/java/me/braydon/mc/model/MinecraftServer.java b/src/main/java/me/braydon/mc/model/MinecraftServer.java index 1c3f180..58ab997 100644 --- a/src/main/java/me/braydon/mc/model/MinecraftServer.java +++ b/src/main/java/me/braydon/mc/model/MinecraftServer.java @@ -31,11 +31,6 @@ public class MinecraftServer { */ @EqualsAndHashCode.Include private final int port; - /** - * The version information of this server. - */ - @NonNull private final Version version; - /** * The player counts of this server. */ @@ -51,45 +46,6 @@ public class MinecraftServer { */ private final String icon; - /** - * Version information for a server. - */ - @AllArgsConstructor @Getter @ToString - public static class Version { - /** - * The version name of the server. - */ - @NonNull private final String name; - - /** - * The identified platform of the server, null if unknown. - */ - private String platform; - - /** - * The protocol version of the server. - */ - private final int protocol; - - /** - * Create a more detailed - * copy of this object. - * - * @return the detailed copy - */ - @NonNull - public Version detailedCopy() { - String platform = null; - if (name.contains(" ")) { // Parse the server platform - String[] split = name.split(" "); - if (split.length == 2) { - platform = split[0]; - } - } - return new Version(name, platform, protocol); - } - } - /** * Player count data for a server. */ diff --git a/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java b/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java index 7ca2789..c2e0081 100644 --- a/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java +++ b/src/main/java/me/braydon/mc/model/server/BedrockMinecraftServer.java @@ -9,8 +9,8 @@ import me.braydon.mc.model.MinecraftServer; * @author Braydon */ public final class BedrockMinecraftServer extends MinecraftServer { - private BedrockMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version, - @NonNull Players players, @NonNull MOTD motd, String icon) { - super(hostname, ip, port, version, players, motd, icon); + private BedrockMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Players players, + @NonNull MOTD motd, String icon) { + super(hostname, ip, port, players, motd, icon); } } \ 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 index 192b96e..1d637a5 100644 --- a/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java +++ b/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java @@ -1,7 +1,10 @@ package me.braydon.mc.model.server; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; +import lombok.ToString; import me.braydon.mc.RESTfulMC; import me.braydon.mc.model.MinecraftServer; import me.braydon.mc.model.token.JavaServerStatusToken; @@ -15,6 +18,16 @@ import net.md_5.bungee.chat.ComponentSerializer; */ @Getter public final class JavaMinecraftServer extends MinecraftServer { + /** + * The version information of this server. + */ + @NonNull private final Version version; + + /** + * The Forge mod information for this server, null if none. + */ + private final ModInfo modInfo; + /** * Does this server enforce secure chat? */ @@ -33,10 +46,12 @@ public final class JavaMinecraftServer extends MinecraftServer { */ private final boolean mojangBanned; - private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version, - @NonNull Players players, @NonNull MOTD motd, String icon, boolean enforcesSecureChat, - boolean preventsChatReports, boolean mojangBanned) { - super(hostname, ip, port, version, players, motd, icon); + private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Players players, + @NonNull MOTD motd, String icon, @NonNull Version version, ModInfo modInfo, + boolean enforcesSecureChat, boolean preventsChatReports, boolean mojangBanned) { + super(hostname, ip, port, players, motd, icon); + this.version = version; + this.modInfo = modInfo; this.enforcesSecureChat = enforcesSecureChat; this.preventsChatReports = preventsChatReports; this.mojangBanned = mojangBanned; @@ -57,8 +72,77 @@ public final class JavaMinecraftServer extends MinecraftServer { if (motdString == null) { // Not a string motd, convert from Json motdString = new TextComponent(ComponentSerializer.parse(RESTfulMC.GSON.toJson(token.getDescription()))).toLegacyText(); } - return new JavaMinecraftServer(hostname, ip, port, token.getVersion().detailedCopy(), token.getPlayers(), - MOTD.create(motdString), token.getFavicon(), token.isEnforcesSecureChat(), token.isPreventsChatReports(), false + return new JavaMinecraftServer(hostname, ip, port, token.getPlayers(), MOTD.create(motdString), + token.getFavicon(), token.getVersion().detailedCopy(), token.getModInfo(), + token.isEnforcesSecureChat(), token.isPreventsChatReports(), false ); } + + /** + * Version information for a server. + */ + @AllArgsConstructor @Getter @ToString + public static class Version { + /** + * The version name of the server. + */ + @NonNull private final String name; + + /** + * The identified platform of the server, null if unknown. + */ + private String platform; + + /** + * The protocol version of the server. + */ + private final int protocol; + + /** + * Create a more detailed + * copy of this object. + * + * @return the detailed copy + */ + @NonNull + public Version detailedCopy() { + String platform = null; + if (name.contains(" ")) { // Parse the server platform + String[] split = name.split(" "); + if (split.length == 2) { + platform = split[0]; + } + } + return new Version(name, platform, protocol); + } + } + + /** + * Forge mod information for a server. + */ + @AllArgsConstructor @Getter @ToString + public static class ModInfo { + /** + * The type of modded server this is. + */ + @NonNull private final String type; + + /** + * The list of mods on this server. + */ + @NonNull private final ForgeMod[] modList; + } + + @AllArgsConstructor @Getter @ToString + private static class ForgeMod { + /** + * The id of this mod. + */ + @NonNull @SerializedName("modid") private final String id; + + /** + * The version of this mod. + */ + private final String version; + } } \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/model/token/JavaServerStatusToken.java b/src/main/java/me/braydon/mc/model/token/JavaServerStatusToken.java index 3ea4375..911f727 100644 --- a/src/main/java/me/braydon/mc/model/token/JavaServerStatusToken.java +++ b/src/main/java/me/braydon/mc/model/token/JavaServerStatusToken.java @@ -1,5 +1,7 @@ package me.braydon.mc.model.token; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; @@ -31,13 +33,18 @@ public final class JavaServerStatusToken { /** * The version information of this server. */ - @NonNull private final MinecraftServer.Version version; + @NonNull private final JavaMinecraftServer.Version version; /** * The player counts of this server. */ @NonNull private final MinecraftServer.Players players; + /** + * The Forge mod information for this server, null if none. + */ + @SerializedName("modinfo") private final JavaMinecraftServer.ModInfo modInfo; + /** * Does this server enforce secure chat? */