From 1a0dd8844d74d7f07303c7ac0a73400a04732492 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 17:40:03 +0100 Subject: [PATCH] fix index and /mojang/status routes --- .../cc/fascinated/controller/HomeController.java | 3 ++- .../cc/fascinated/controller/MojangController.java | 3 ++- src/main/java/cc/fascinated/model/player/Player.java | 6 +++--- .../MojangProfileToken.java} | 4 ++-- .../MojangUsernameToUuidToken.java} | 4 ++-- .../java/cc/fascinated/service/MojangService.java | 12 ++++++------ .../java/cc/fascinated/service/PlayerService.java | 8 ++++---- 7 files changed, 21 insertions(+), 19 deletions(-) rename src/main/java/cc/fascinated/model/{mojang/MojangProfile.java => token/MojangProfileToken.java} (97%) rename src/main/java/cc/fascinated/model/{mojang/MojangUsernameToUuid.java => token/MojangUsernameToUuidToken.java} (87%) diff --git a/src/main/java/cc/fascinated/controller/HomeController.java b/src/main/java/cc/fascinated/controller/HomeController.java index bdeade8..433f7ab 100644 --- a/src/main/java/cc/fascinated/controller/HomeController.java +++ b/src/main/java/cc/fascinated/controller/HomeController.java @@ -3,6 +3,7 @@ package cc.fascinated.controller; import cc.fascinated.config.Config; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @@ -15,7 +16,7 @@ public class HomeController { private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String exampleServer = "aetheria.cc"; - @RequestMapping(value = "/") + @GetMapping(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); diff --git a/src/main/java/cc/fascinated/controller/MojangController.java b/src/main/java/cc/fascinated/controller/MojangController.java index 0e96512..3e372d9 100644 --- a/src/main/java/cc/fascinated/controller/MojangController.java +++ b/src/main/java/cc/fascinated/controller/MojangController.java @@ -5,6 +5,7 @@ import cc.fascinated.service.MojangService; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @@ -18,7 +19,7 @@ public class MojangController { private MojangService mojangService; @ResponseBody - @RequestMapping(value = "/status") + @GetMapping(value = "/status") public CachedEndpointStatus getStatus() { return mojangService.getMojangApiStatus(); } diff --git a/src/main/java/cc/fascinated/model/player/Player.java b/src/main/java/cc/fascinated/model/player/Player.java index 7c4608c..9db175f 100644 --- a/src/main/java/cc/fascinated/model/player/Player.java +++ b/src/main/java/cc/fascinated/model/player/Player.java @@ -2,7 +2,7 @@ package cc.fascinated.model.player; import cc.fascinated.common.Tuple; import cc.fascinated.common.UUIDUtils; -import cc.fascinated.model.mojang.MojangProfile; +import cc.fascinated.model.token.MojangProfileToken; import cc.fascinated.model.skin.Skin; import lombok.AllArgsConstructor; import lombok.Getter; @@ -43,9 +43,9 @@ public class Player { /** * The raw properties of the player */ - private MojangProfile.ProfileProperty[] rawProperties; + private MojangProfileToken.ProfileProperty[] rawProperties; - public Player(MojangProfile profile) { + public Player(MojangProfileToken profile) { this.uniqueId = UUIDUtils.addDashes(profile.getId()); this.trimmedUniqueId = UUIDUtils.removeDashes(this.uniqueId); this.username = profile.getName(); diff --git a/src/main/java/cc/fascinated/model/mojang/MojangProfile.java b/src/main/java/cc/fascinated/model/token/MojangProfileToken.java similarity index 97% rename from src/main/java/cc/fascinated/model/mojang/MojangProfile.java rename to src/main/java/cc/fascinated/model/token/MojangProfileToken.java index 089178c..1fe4612 100644 --- a/src/main/java/cc/fascinated/model/mojang/MojangProfile.java +++ b/src/main/java/cc/fascinated/model/token/MojangProfileToken.java @@ -1,4 +1,4 @@ -package cc.fascinated.model.mojang; +package cc.fascinated.model.token; import cc.fascinated.Main; import cc.fascinated.common.Tuple; @@ -14,7 +14,7 @@ import lombok.NoArgsConstructor; import java.util.Base64; @Getter @NoArgsConstructor @AllArgsConstructor -public class MojangProfile { +public class MojangProfileToken { /** * The UUID of the player. diff --git a/src/main/java/cc/fascinated/model/mojang/MojangUsernameToUuid.java b/src/main/java/cc/fascinated/model/token/MojangUsernameToUuidToken.java similarity index 87% rename from src/main/java/cc/fascinated/model/mojang/MojangUsernameToUuid.java rename to src/main/java/cc/fascinated/model/token/MojangUsernameToUuidToken.java index 2be84bc..a9e1c18 100644 --- a/src/main/java/cc/fascinated/model/mojang/MojangUsernameToUuid.java +++ b/src/main/java/cc/fascinated/model/token/MojangUsernameToUuidToken.java @@ -1,11 +1,11 @@ -package cc.fascinated.model.mojang; +package cc.fascinated.model.token; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor -public class MojangUsernameToUuid { +public class MojangUsernameToUuidToken { /** * The UUID of the player. diff --git a/src/main/java/cc/fascinated/service/MojangService.java b/src/main/java/cc/fascinated/service/MojangService.java index 18aac29..d614ed1 100644 --- a/src/main/java/cc/fascinated/service/MojangService.java +++ b/src/main/java/cc/fascinated/service/MojangService.java @@ -6,8 +6,8 @@ import cc.fascinated.common.ExpiringSet; import cc.fascinated.common.WebRequest; import cc.fascinated.config.Config; import cc.fascinated.model.cache.CachedEndpointStatus; -import cc.fascinated.model.mojang.MojangProfile; -import cc.fascinated.model.mojang.MojangUsernameToUuid; +import cc.fascinated.model.token.MojangProfileToken; +import cc.fascinated.model.token.MojangUsernameToUuidToken; import cc.fascinated.repository.EndpointStatusRepository; import com.google.common.base.Joiner; import com.google.common.base.Splitter; @@ -244,8 +244,8 @@ public class MojangService { * @param id the uuid or name of the player * @return the profile */ - public MojangProfile getProfile(String id) { - return WebRequest.getAsEntity(SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/" + id, MojangProfile.class); + public MojangProfileToken getProfile(String id) { + return WebRequest.getAsEntity(SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/" + id, MojangProfileToken.class); } /** @@ -255,7 +255,7 @@ public class MojangService { * @param id the name of the player * @return the profile */ - public MojangUsernameToUuid getUuidFromUsername(String id) { - return WebRequest.getAsEntity(API_ENDPOINT + "/users/profiles/minecraft/" + id, MojangUsernameToUuid.class); + public MojangUsernameToUuidToken getUuidFromUsername(String id) { + return WebRequest.getAsEntity(API_ENDPOINT + "/users/profiles/minecraft/" + id, MojangUsernameToUuidToken.class); } } diff --git a/src/main/java/cc/fascinated/service/PlayerService.java b/src/main/java/cc/fascinated/service/PlayerService.java index 7f01fb8..5fc4a59 100644 --- a/src/main/java/cc/fascinated/service/PlayerService.java +++ b/src/main/java/cc/fascinated/service/PlayerService.java @@ -12,8 +12,8 @@ import cc.fascinated.exception.impl.ResourceNotFoundException; import cc.fascinated.model.cache.CachedPlayer; import cc.fascinated.model.cache.CachedPlayerName; import cc.fascinated.model.cache.CachedPlayerSkinPart; -import cc.fascinated.model.mojang.MojangProfile; -import cc.fascinated.model.mojang.MojangUsernameToUuid; +import cc.fascinated.model.token.MojangProfileToken; +import cc.fascinated.model.token.MojangUsernameToUuidToken; import cc.fascinated.model.player.Cape; import cc.fascinated.model.player.Player; import cc.fascinated.model.skin.ISkinPart; @@ -69,7 +69,7 @@ public class PlayerService { try { log.info("Getting player profile from Mojang: {}", id); - MojangProfile mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang + MojangProfileToken mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang log.info("Got player profile from Mojang: {}", id); Tuple skinAndCape = mojangProfile.getSkinAndCape(); CachedPlayer player = new CachedPlayer( @@ -106,7 +106,7 @@ public class PlayerService { return cachedPlayerName.get(); } try { - MojangUsernameToUuid mojangUsernameToUuid = mojangAPIService.getUuidFromUsername(username); + MojangUsernameToUuidToken mojangUsernameToUuid = mojangAPIService.getUuidFromUsername(username); if (mojangUsernameToUuid == null) { log.info("Player with username '{}' not found", username); throw new ResourceNotFoundException("Player with username '%s' not found".formatted(username));