From 63a3587586153200f111b98e916f91b7ae1c8cfe Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 10 Apr 2024 13:24:56 +0100 Subject: [PATCH] add mods and plugins to server response --- pom.xml | 8 ---- src/main/java/cc.fascinated/Main.java | 5 ++- .../cc.fascinated/common/PlayerUtils.java | 2 +- .../cc.fascinated/common/ServerUtils.java | 1 - .../java/cc.fascinated/config/Config.java | 2 +- .../controller/ServerController.java | 2 - .../model/cache/CachedPlayerSkinPart.java | 5 ++- .../model/mojang/JavaServerStatusToken.java | 10 +++++ .../model/server/JavaMinecraftServer.java | 21 ++++++++-- .../model/server/MinecraftServer.java | 38 ++++++++++++++++++- .../PlayerSkinPartCacheRepository.java | 1 - src/main/resources/application.yml | 11 ++++-- 12 files changed, 82 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 2ee2129..380347b 100644 --- a/pom.xml +++ b/pom.xml @@ -59,14 +59,6 @@ org.springframework.boot spring-boot-starter-web - - - - - org.springframework.boot - spring-boot-starter-json - - diff --git a/src/main/java/cc.fascinated/Main.java b/src/main/java/cc.fascinated/Main.java index f9d0709..079df56 100644 --- a/src/main/java/cc.fascinated/Main.java +++ b/src/main/java/cc.fascinated/Main.java @@ -1,6 +1,7 @@ package cc.fascinated; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import org.springframework.boot.SpringApplication; @@ -16,7 +17,9 @@ import java.util.Objects; @SpringBootApplication public class Main { - public static final Gson GSON = new Gson(); + public static final Gson GSON = new GsonBuilder() + .setDateFormat("MM-dd-yyyy HH:mm:ss") + .create(); public static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient(); @SneakyThrows diff --git a/src/main/java/cc.fascinated/common/PlayerUtils.java b/src/main/java/cc.fascinated/common/PlayerUtils.java index 090ef43..8020dda 100644 --- a/src/main/java/cc.fascinated/common/PlayerUtils.java +++ b/src/main/java/cc.fascinated/common/PlayerUtils.java @@ -60,7 +60,7 @@ public class PlayerUtils { * @return the part data */ public static byte[] getSkinPartBytes(Skin skin, Skin.Parts part, int size) { - if (size == -1) { + if (size <= 0) { size = part.getDefaultSize(); } diff --git a/src/main/java/cc.fascinated/common/ServerUtils.java b/src/main/java/cc.fascinated/common/ServerUtils.java index 945fc48..acee04b 100644 --- a/src/main/java/cc.fascinated/common/ServerUtils.java +++ b/src/main/java/cc.fascinated/common/ServerUtils.java @@ -1,6 +1,5 @@ package cc.fascinated.common; -import cc.fascinated.exception.impl.BadRequestException; import lombok.experimental.UtilityClass; @UtilityClass diff --git a/src/main/java/cc.fascinated/config/Config.java b/src/main/java/cc.fascinated/config/Config.java index 2aac78f..4da4c21 100644 --- a/src/main/java/cc.fascinated/config/Config.java +++ b/src/main/java/cc.fascinated/config/Config.java @@ -5,8 +5,8 @@ import lombok.Getter; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -@Configuration @Getter +@Configuration public class Config { public static Config INSTANCE; diff --git a/src/main/java/cc.fascinated/controller/ServerController.java b/src/main/java/cc.fascinated/controller/ServerController.java index a69c2c3..a44e66e 100644 --- a/src/main/java/cc.fascinated/controller/ServerController.java +++ b/src/main/java/cc.fascinated/controller/ServerController.java @@ -1,7 +1,5 @@ package cc.fascinated.controller; -import cc.fascinated.common.ServerUtils; -import cc.fascinated.common.Tuple; import cc.fascinated.model.cache.CachedMinecraftServer; import cc.fascinated.service.MojangService; import cc.fascinated.service.ServerService; diff --git a/src/main/java/cc.fascinated/model/cache/CachedPlayerSkinPart.java b/src/main/java/cc.fascinated/model/cache/CachedPlayerSkinPart.java index a97bf2c..a35210c 100644 --- a/src/main/java/cc.fascinated/model/cache/CachedPlayerSkinPart.java +++ b/src/main/java/cc.fascinated/model/cache/CachedPlayerSkinPart.java @@ -1,6 +1,9 @@ package cc.fascinated.model.cache; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; import org.springframework.data.annotation.Id; import org.springframework.data.redis.core.RedisHash; diff --git a/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java b/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java index cb4aa0a..db8489f 100644 --- a/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java +++ b/src/main/java/cc.fascinated/model/mojang/JavaServerStatusToken.java @@ -22,6 +22,16 @@ public final class JavaServerStatusToken { */ private final MinecraftServer.Players players; + /** + * The mods running on the server. + */ + private final MinecraftServer.Mod[] mods; + + /** + * The plugins running on the server. + */ + private final MinecraftServer.Plugin[] plugins; + /** * 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 70f7877..e503991 100644 --- a/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java +++ b/src/main/java/cc.fascinated/model/server/JavaMinecraftServer.java @@ -28,15 +28,28 @@ public final class JavaMinecraftServer extends MinecraftServer { */ private Favicon favicon; + /** + * The mods of the server. + */ + private MinecraftServer.Mod[] mods; + + /** + * The plugins of the server. + */ + private MinecraftServer.Plugin[] plugins; + /** * The mojang banned status of the server. */ private boolean mojangBanned; - public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, @NonNull Version version, Players players, Favicon favicon) { + public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, Players players, + @NonNull Version version, Favicon favicon, Mod[] mods, Plugin[] plugins) { super(hostname, ip, port, motd, players); this.version = version; this.favicon = favicon; + this.mods = mods; + this.plugins = plugins; } /** @@ -59,9 +72,11 @@ public final class JavaMinecraftServer extends MinecraftServer { ip, port, MinecraftServer.MOTD.create(motdString), - token.getVersion().detailedCopy(), token.getPlayers(), - JavaMinecraftServer.Favicon.create(token.getFavicon(), ServerUtils.getAddress(hostname, port)) + token.getVersion().detailedCopy(), + JavaMinecraftServer.Favicon.create(token.getFavicon(), ServerUtils.getAddress(hostname, port)), + token.getMods(), + token.getPlugins() ); } diff --git a/src/main/java/cc.fascinated/model/server/MinecraftServer.java b/src/main/java/cc.fascinated/model/server/MinecraftServer.java index f4889d3..9c1f593 100644 --- a/src/main/java/cc.fascinated/model/server/MinecraftServer.java +++ b/src/main/java/cc.fascinated/model/server/MinecraftServer.java @@ -108,7 +108,7 @@ public class MinecraftServer { /** * Player count data for a server. */ - @AllArgsConstructor @Getter @ToString + @AllArgsConstructor @Getter public static class Players { /** * The online players on this server. @@ -141,4 +141,40 @@ 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/repository/PlayerSkinPartCacheRepository.java b/src/main/java/cc.fascinated/repository/PlayerSkinPartCacheRepository.java index b23d18e..aa32f01 100644 --- a/src/main/java/cc.fascinated/repository/PlayerSkinPartCacheRepository.java +++ b/src/main/java/cc.fascinated/repository/PlayerSkinPartCacheRepository.java @@ -1,6 +1,5 @@ package cc.fascinated.repository; -import cc.fascinated.model.cache.CachedPlayerName; import cc.fascinated.model.cache.CachedPlayerSkinPart; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6af6b8f..d2ce0dd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,9 +3,9 @@ server: port: 80 servlet: context-path: / - error: - whitelabel: - enabled: false + +# The public URL of the application +public-url: http://localhost:80 # Spring Configuration spring: @@ -17,4 +17,7 @@ spring: database: 0 auth: "" # Leave blank for no auth -public-url: http://localhost:80 \ No newline at end of file + # Don't serialize null values + jackson: + default-property-inclusion: non_null +