From cd3738a2b91d236aa49491b3ad3dfadfc3a88b37 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 10 Apr 2024 14:03:35 +0100 Subject: [PATCH] add legacy forge mod and new forge mod support --- .../model/mojang/JavaServerStatusToken.java | 14 ++- .../model/server/JavaMinecraftServer.java | 105 +++++++++++++++--- .../model/server/MinecraftServer.java | 36 ------ .../impl/JavaMinecraftServerPinger.java | 1 + target/classes/application.yml | 11 +- 5 files changed, 110 insertions(+), 57 deletions(-) diff --git a/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java b/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java index db8489f..0b5c9b8 100644 --- a/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java +++ b/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java @@ -2,6 +2,7 @@ package cc.fascinated.model.mojang; import cc.fascinated.model.server.JavaMinecraftServer; import cc.fascinated.model.server.MinecraftServer; +import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; @@ -23,14 +24,19 @@ public final class JavaServerStatusToken { private final MinecraftServer.Players players; /** - * The mods running on the server. + * The mods running on this server. */ - private final MinecraftServer.Mod[] mods; + @SerializedName("modinfo") + private JavaMinecraftServer.ForgeModInfo modInfo; /** - * The plugins running on the server. + * The mods running on this server. + *

+ * This is only used for servers + * running 1.13 and above. + *

*/ - private final MinecraftServer.Plugin[] plugins; + private JavaMinecraftServer.ForgeData forgeData; /** * The motd of the server. diff --git a/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java b/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java index e503991..d827701 100644 --- a/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java +++ b/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java @@ -5,10 +5,8 @@ import cc.fascinated.common.JavaMinecraftVersion; import cc.fascinated.common.ServerUtils; import cc.fascinated.config.Config; import cc.fascinated.model.mojang.JavaServerStatusToken; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; +import com.google.gson.annotations.SerializedName; +import lombok.*; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -29,14 +27,18 @@ public final class JavaMinecraftServer extends MinecraftServer { private Favicon favicon; /** - * The mods of the server. + * The mods running on this server. */ - private MinecraftServer.Mod[] mods; + private ForgeModInfo modInfo; /** - * The plugins of the server. + * The mods running on this server. + *

+ * This is only used for servers + * running 1.13 and above. + *

*/ - private MinecraftServer.Plugin[] plugins; + private ForgeData forgeData; /** * The mojang banned status of the server. @@ -44,12 +46,12 @@ public final class JavaMinecraftServer extends MinecraftServer { private boolean mojangBanned; public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, Players players, - @NonNull Version version, Favicon favicon, Mod[] mods, Plugin[] plugins) { + @NonNull Version version, Favicon favicon, ForgeModInfo modInfo, ForgeData forgeData) { super(hostname, ip, port, motd, players); this.version = version; this.favicon = favicon; - this.mods = mods; - this.plugins = plugins; + this.modInfo = modInfo; + this.forgeData = forgeData; } /** @@ -75,8 +77,8 @@ public final class JavaMinecraftServer extends MinecraftServer { token.getPlayers(), token.getVersion().detailedCopy(), JavaMinecraftServer.Favicon.create(token.getFavicon(), ServerUtils.getAddress(hostname, port)), - token.getMods(), - token.getPlugins() + token.getModInfo(), + token.getForgeData() ); } @@ -151,4 +153,81 @@ public final class JavaMinecraftServer extends MinecraftServer { return new Favicon(base64, Config.INSTANCE.getWebPublicUrl() + "/server/icon/%s".formatted(address)); } } + + /** + * Forge mod information for a server. + */ + @AllArgsConstructor @Getter @ToString + public static class ForgeModInfo { + /** + * The type of modded server this is. + */ + @NonNull private final String type; + + /** + * The list of mods on this server, null or empty if none. + */ + private final ForgeMod[] modList; + + /** + * A forge mod for a server. + */ + @AllArgsConstructor @Getter @ToString + private static class ForgeMod { + /** + * The id of this mod. + */ + @NonNull @SerializedName("modid") private final String name; + + /** + * The version of this mod. + */ + private final String version; + } + } + + @AllArgsConstructor @Getter + public static class ForgeData { + + /** + * The list of mod channels on this server, null or empty if none. + */ + private final Channel[] channels; + + /** + * The list of mods on this server, null or empty if none. + */ + private final Mod[] mods; + + @AllArgsConstructor @Getter + public static class Channel { + /** + * The id of this mod channel. + */ + @NonNull @SerializedName("res") private final String name; + + /** + * The version of this mod channel. + */ + private final String version; + + /** + * Whether this mod channel is required to join. + */ + private boolean required; + } + + @AllArgsConstructor @Getter + public static class Mod { + /** + * The id of this mod. + */ + @NonNull @SerializedName("modId") private final String name; + + /** + * The version of this mod. + */ + @SerializedName("modmarker") private final String version; + } + } } \ No newline at end of file diff --git a/src/main/java/cc.fascinated/model/server/MinecraftServer.java b/src/main/java/cc.fascinated/model/server/MinecraftServer.java index 9c1f593..6c80e7b 100644 --- a/src/main/java/cc.fascinated/model/server/MinecraftServer.java +++ b/src/main/java/cc.fascinated/model/server/MinecraftServer.java @@ -141,40 +141,4 @@ public class MinecraftServer { @NonNull private final String name; } } - - /** - * Mod data for a server. - */ - @AllArgsConstructor @Getter - public static final class Mod { - - /** - * The name of the mod. - */ - private final String name; - - - /** - * The version of the mod. - */ - private final String version; - } - - /** - * Plugin data for a server. - */ - @AllArgsConstructor @Getter - public static final class Plugin { - - /** - * The name of the plugin. - */ - private final String name; - - - /** - * The version of the plugin. - */ - private final String version; - } } \ No newline at end of file diff --git a/src/main/java/cc.fascinated/service/pinger/impl/JavaMinecraftServerPinger.java b/src/main/java/cc.fascinated/service/pinger/impl/JavaMinecraftServerPinger.java index 60aec37..fc2e3f0 100644 --- a/src/main/java/cc.fascinated/service/pinger/impl/JavaMinecraftServerPinger.java +++ b/src/main/java/cc.fascinated/service/pinger/impl/JavaMinecraftServerPinger.java @@ -47,6 +47,7 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger