From 3347ac6dcb8c81169456a37fb8130d1394c04176 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sat, 6 Apr 2024 14:46:42 -0400 Subject: [PATCH] Slight refactor --- .../mc/model/token/MojangUsernameToUUIDToken.java | 5 ++++- src/main/java/me/braydon/mc/service/MojangAPI.java | 13 ------------- .../java/me/braydon/mc/service/MojangService.java | 9 +++++++-- 3 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/me/braydon/mc/service/MojangAPI.java diff --git a/src/main/java/me/braydon/mc/model/token/MojangUsernameToUUIDToken.java b/src/main/java/me/braydon/mc/model/token/MojangUsernameToUUIDToken.java index 4765e95..fdf7cd1 100644 --- a/src/main/java/me/braydon/mc/model/token/MojangUsernameToUUIDToken.java +++ b/src/main/java/me/braydon/mc/model/token/MojangUsernameToUUIDToken.java @@ -1,6 +1,9 @@ package me.braydon.mc.model.token; -import lombok.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; /** * A token representing a Mojang username to UUID response. diff --git a/src/main/java/me/braydon/mc/service/MojangAPI.java b/src/main/java/me/braydon/mc/service/MojangAPI.java deleted file mode 100644 index 7a5120d..0000000 --- a/src/main/java/me/braydon/mc/service/MojangAPI.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.braydon.mc.service; - -/** - * Endpoints for the Mojang API. - * - * @author Braydon - */ -public class MojangAPI { - private static final String SESSION_SERVER_ENDPOINT = "https://sessionserver.mojang.com"; - private static final String API_ENDPOINT = "https://api.mojang.com"; - protected static final String UUID_TO_PROFILE = SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/%s"; - protected static final String USERNAME_TO_UUID = API_ENDPOINT + "/users/profiles/minecraft/%s"; -} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/service/MojangService.java b/src/main/java/me/braydon/mc/service/MojangService.java index fb76975..9d4bc7f 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -23,6 +23,11 @@ import java.util.UUID; @Service @Log4j2(topic = "Mojang Service") public final class MojangService { + private static final String SESSION_SERVER_ENDPOINT = "https://sessionserver.mojang.com"; + private static final String API_ENDPOINT = "https://api.mojang.com"; + private static final String UUID_TO_PROFILE = SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/%s"; + private static final String USERNAME_TO_UUID = API_ENDPOINT + "/users/profiles/minecraft/%s"; + /** * Get a player by their username or UUID. * @@ -54,7 +59,7 @@ public final class MojangService { try { log.info("Retrieving player profile for UUID: {}", uuid); MojangProfileToken token = JsonWebRequest.makeRequest( - MojangAPI.UUID_TO_PROFILE.formatted(uuid), HttpMethod.GET + UUID_TO_PROFILE.formatted(uuid), HttpMethod.GET ).execute(MojangProfileToken.class); // Return our player model representing the requested player @@ -80,7 +85,7 @@ public final class MojangService { // Make a request to Mojang requesting the UUID try { MojangUsernameToUUIDToken token = JsonWebRequest.makeRequest( - MojangAPI.USERNAME_TO_UUID.formatted(username), HttpMethod.GET + USERNAME_TO_UUID.formatted(username), HttpMethod.GET ).execute(MojangUsernameToUUIDToken.class); return UUIDUtils.addDashes(token.getId()); // Return the UUID with dashes } catch (JsonWebException ex) {