From fd16430307625cb7dc519f678459d3ca9837b397 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 18 Apr 2024 13:09:23 -0400 Subject: [PATCH] Update the return json of /mojang/status in the API --- .../java/me/braydon/mc/common/MojangServer.java | 15 ++++++++++----- .../braydon/mc/controller/MojangController.java | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/API/src/main/java/me/braydon/mc/common/MojangServer.java b/API/src/main/java/me/braydon/mc/common/MojangServer.java index 537df1f..0a5cfde 100644 --- a/API/src/main/java/me/braydon/mc/common/MojangServer.java +++ b/API/src/main/java/me/braydon/mc/common/MojangServer.java @@ -39,14 +39,19 @@ import java.net.UnknownHostException; */ @AllArgsConstructor @Getter @ToString public enum MojangServer { - SESSION("https://sessionserver.mojang.com"), - API("https://api.mojang.com"), - TEXTURES("https://textures.minecraft.net"), - ASSETS("https://assets.mojang.com"), - LIBRARIES("https://libraries.minecraft.net"); + SESSION("Session Server", "https://sessionserver.mojang.com"), + API("Mojang API", "https://api.mojang.com"), + TEXTURES("Textures Server", "https://textures.minecraft.net"), + ASSETS("Assets Server", "https://assets.mojang.com"), + LIBRARIES("Libraries Server", "https://libraries.minecraft.net"); private static final int STATUS_TIMEOUT = 7000; + /** + * The name of this server. + */ + @NonNull private final String name; + /** * The endpoint of this service. */ diff --git a/API/src/main/java/me/braydon/mc/controller/MojangController.java b/API/src/main/java/me/braydon/mc/controller/MojangController.java index 2ff2c5e..219900b 100644 --- a/API/src/main/java/me/braydon/mc/controller/MojangController.java +++ b/API/src/main/java/me/braydon/mc/controller/MojangController.java @@ -37,7 +37,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -68,11 +70,17 @@ public final class MojangController { */ @GetMapping("/status") @ResponseBody - public ResponseEntity> getStatus() throws BadRequestException { - Map response = new HashMap<>(); + public ResponseEntity>>> getStatus() throws BadRequestException { + List> servers = new ArrayList<>(); for (Map.Entry entry : mojangService.getMojangServerStatuses().entrySet()) { - response.put(entry.getKey().getEndpoint(), entry.getValue().name()); + MojangServer server = entry.getKey(); + + Map serverStatus = new HashMap<>(); + serverStatus.put("name", server.getName()); + serverStatus.put("endpoint", server.getEndpoint()); + serverStatus.put("status", entry.getValue().name()); + servers.add(serverStatus); } - return ResponseEntity.ok(response); + return ResponseEntity.ok(Map.of("servers", servers)); } } \ No newline at end of file