From 160fed45e875cbc2e2253837be8e5766b069e7c9 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 10 Apr 2024 11:18:42 -0400 Subject: [PATCH] Tuple -> SkinProperties --- src/main/java/me/braydon/mc/common/Tuple.java | 47 ------------------- src/main/java/me/braydon/mc/model/Skin.java | 4 +- .../mc/model/token/MojangProfileToken.java | 28 ++++++++--- .../me/braydon/mc/service/MojangService.java | 11 +++-- 4 files changed, 31 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/me/braydon/mc/common/Tuple.java diff --git a/src/main/java/me/braydon/mc/common/Tuple.java b/src/main/java/me/braydon/mc/common/Tuple.java deleted file mode 100644 index 742c10e..0000000 --- a/src/main/java/me/braydon/mc/common/Tuple.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024 Braydon (Rainnny). - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package me.braydon.mc.common; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -/** - * A simple tuple utility. - * - * @author Braydon - */ -@NoArgsConstructor @AllArgsConstructor @Setter @Getter -public class Tuple { - /** - * The left value. - */ - private L left; - - /** - * The right value. - */ - private R right; -} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/model/Skin.java b/src/main/java/me/braydon/mc/model/Skin.java index 5fcd563..9a857a1 100644 --- a/src/main/java/me/braydon/mc/model/Skin.java +++ b/src/main/java/me/braydon/mc/model/Skin.java @@ -23,8 +23,8 @@ */ package me.braydon.mc.model; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.JsonObject; -import com.google.gson.annotations.SerializedName; import lombok.*; import me.braydon.mc.common.ImageUtils; import me.braydon.mc.config.AppConfig; @@ -54,7 +54,7 @@ public final class Skin { /** * URLs to the parts of this skin. */ - @NonNull @SerializedName("parts") private Map partUrls = new HashMap<>(); + @NonNull @JsonProperty("parts") private Map partUrls = new HashMap<>(); /** * Populate the part URLs for this skin. diff --git a/src/main/java/me/braydon/mc/model/token/MojangProfileToken.java b/src/main/java/me/braydon/mc/model/token/MojangProfileToken.java index d3da2f8..72b1dd2 100644 --- a/src/main/java/me/braydon/mc/model/token/MojangProfileToken.java +++ b/src/main/java/me/braydon/mc/model/token/MojangProfileToken.java @@ -25,7 +25,6 @@ package me.braydon.mc.model.token; import com.google.gson.JsonObject; import lombok.*; -import me.braydon.mc.common.Tuple; import me.braydon.mc.config.AppConfig; import me.braydon.mc.model.Cape; import me.braydon.mc.model.ProfileAction; @@ -62,20 +61,21 @@ public final class MojangProfileToken { @NonNull private final ProfileAction[] profileActions; /** - * Get the skin and cape of this profile. + * Get the properties of this skin. * - * @return the skin and cape of this profile + * @return the properties */ - public Tuple getSkinAndCape() { + @NonNull + public SkinProperties getSkinProperties() { ProfileProperty textures = getPropertyByName("textures"); // Get the profile textures if (textures == null) { // No profile textures - return new Tuple<>(); + return new SkinProperties(); } JsonObject jsonObject = AppConfig.GSON.fromJson(textures.getDecodedValue(), JsonObject.class); // Get the Json object JsonObject texturesJsonObject = jsonObject.getAsJsonObject("textures"); // Get the textures object // Return the tuple containing the skin and cape - return new Tuple<>( + return new SkinProperties( Skin.fromJsonObject(texturesJsonObject.getAsJsonObject("SKIN")).populatePartUrls(id), Cape.fromJsonObject(texturesJsonObject.getAsJsonObject("CAPE")) ); @@ -137,4 +137,20 @@ public final class MojangProfileToken { return signature != null; } } + + /** + * The properties for a skin. + */ + @NoArgsConstructor @AllArgsConstructor @Getter @ToString + public static class SkinProperties { + /** + * The skin of the profile. + */ + private Skin skin; + + /** + * The cape of the profile. + */ + private Cape cape; + } } \ 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 fa5e452..0b7b84c 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -37,7 +37,10 @@ import me.braydon.mc.common.web.JsonWebRequest; import me.braydon.mc.exception.impl.BadRequestException; import me.braydon.mc.exception.impl.MojangRateLimitException; import me.braydon.mc.exception.impl.ResourceNotFoundException; -import me.braydon.mc.model.*; +import me.braydon.mc.model.MinecraftServer; +import me.braydon.mc.model.Player; +import me.braydon.mc.model.ProfileAction; +import me.braydon.mc.model.Skin; import me.braydon.mc.model.cache.CachedMinecraftServer; import me.braydon.mc.model.cache.CachedPlayer; import me.braydon.mc.model.cache.CachedPlayerName; @@ -257,14 +260,14 @@ public final class MojangService { MojangProfileToken token = JsonWebRequest.makeRequest( UUID_TO_PROFILE.formatted(uuid), HttpMethod.GET ).execute(MojangProfileToken.class); - Tuple skinAndCape = token.getSkinAndCape(); // Get the skin and cape + MojangProfileToken.SkinProperties skinProperties = token.getSkinProperties(); // Get the skin and cape ProfileAction[] profileActions = token.getProfileActions(); // Build our player model, cache it, and then return it CachedPlayer player = new CachedPlayer( uuid, token.getName(), - skinAndCape.getLeft() == null ? Skin.DEFAULT_STEVE : skinAndCape.getLeft(), - skinAndCape.getRight(), + skinProperties.getSkin() == null ? Skin.DEFAULT_STEVE : skinProperties.getSkin(), + skinProperties.getCape(), profileActions.length == 0 ? null : profileActions, System.currentTimeMillis() );