From a3b9cb5e7765b23fa545f17fcd8d29a49b0e7486 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 11 Apr 2024 00:21:36 +0100 Subject: [PATCH] fix server example and add an endpoint to get uuid from username --- .../cc.fascinated/controller/HomeController.java | 4 ++-- .../cc.fascinated/controller/PlayerController.java | 12 ++++++++++++ .../cc.fascinated/controller/ServerController.java | 6 +++--- .../java/cc.fascinated/service/PlayerService.java | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/cc.fascinated/controller/HomeController.java b/src/main/java/cc.fascinated/controller/HomeController.java index 14aa159..a02fac2 100644 --- a/src/main/java/cc.fascinated/controller/HomeController.java +++ b/src/main/java/cc.fascinated/controller/HomeController.java @@ -13,13 +13,13 @@ public class HomeController { * The example UUID. */ private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; - private final String exampleServer = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; + private final String exampleServer = "aetheria.cc"; @RequestMapping(value = "/") public String home(Model model) { model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid); model.addAttribute("java_server_example_url", Config.INSTANCE.getWebPublicUrl() + "/server/java/" + exampleServer); - model.addAttribute("swagger_url", Config.INSTANCE.getWebPublicUrl() + "/docs"); + model.addAttribute("swagger_url", Config.INSTANCE.getWebPublicUrl() + "/swagger-ui.html"); return "index"; } } diff --git a/src/main/java/cc.fascinated/controller/PlayerController.java b/src/main/java/cc.fascinated/controller/PlayerController.java index 6e49693..4638c58 100644 --- a/src/main/java/cc.fascinated/controller/PlayerController.java +++ b/src/main/java/cc.fascinated/controller/PlayerController.java @@ -12,6 +12,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.Map; import java.util.concurrent.TimeUnit; @RestController @@ -36,6 +37,17 @@ public class PlayerController { .body(playerService.getPlayer(id)); } + @ResponseBody + @GetMapping(value = "/uuid/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getPlayerUuid( + @Parameter(description = "The UUID or Username of the player", example = "ImFascinated") @PathVariable String id) { + CachedPlayer player = playerService.getPlayer(id); + return ResponseEntity.ok(Map.of( + "username", player.getUsername(), + "uuid", player.getUuid().toString() + )); + } + @GetMapping(value = "/{part}/{id}") public ResponseEntity getPlayerHead( @Parameter(description = "The part of the skin", example = "head") @PathVariable String part, diff --git a/src/main/java/cc.fascinated/controller/ServerController.java b/src/main/java/cc.fascinated/controller/ServerController.java index 60a8867..06eb6ab 100644 --- a/src/main/java/cc.fascinated/controller/ServerController.java +++ b/src/main/java/cc.fascinated/controller/ServerController.java @@ -31,14 +31,14 @@ public class ServerController { @GetMapping(value = "/{platform}/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE) public CachedMinecraftServer getServer( @Parameter(description = "The platform of the server", example = "java") @PathVariable String platform, - @Parameter(description = "The hostname and port of the server", example = "play.hypixel.net") @PathVariable String hostname) { + @Parameter(description = "The hostname and port of the server", example = "aetheria.cc") @PathVariable String hostname) { return serverService.getServer(platform, hostname); } @ResponseBody @GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE) public ResponseEntity getServerIcon( - @Parameter(description = "The hostname and port of the server", example = "play.hypixel.net") @PathVariable String hostname, + @Parameter(description = "The hostname and port of the server", example = "aetheria.cc") @PathVariable String hostname, @Parameter(description = "Whether to download the image") @RequestParam(required = false, defaultValue = "false") boolean download) { String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png"; @@ -51,7 +51,7 @@ public class ServerController { @ResponseBody @GetMapping(value = "/blocked/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getServerBlockedStatus( - @Parameter(description = "The hostname of the server", example = "play.hypixel.net") @PathVariable String hostname) { + @Parameter(description = "The hostname of the server", example = "aetheria.cc") @PathVariable String hostname) { return ResponseEntity.ok(Map.of( "blocked", mojangService.isServerBlocked(hostname) )); diff --git a/src/main/java/cc.fascinated/service/PlayerService.java b/src/main/java/cc.fascinated/service/PlayerService.java index 6b8ce4e..78c06ba 100644 --- a/src/main/java/cc.fascinated/service/PlayerService.java +++ b/src/main/java/cc.fascinated/service/PlayerService.java @@ -91,7 +91,7 @@ public class PlayerService { * @param username the username of the player * @return the uuid of the player */ - private UUID usernameToUuid(String username) { + public UUID usernameToUuid(String username) { log.info("Getting UUID from username: {}", username); Optional cachedPlayerName = playerNameCacheRepository.findById(username.toUpperCase()); if (cachedPlayerName.isPresent()) {