From 3cf16bd2ebb067dcce170e4dcb1a1b5c5a6ff7a9 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 15:54:32 +0100 Subject: [PATCH] add fallback skins --- .../java/cc/fascinated/common/WebRequest.java | 8 ++++---- src/main/java/cc/fascinated/model/skin/Skin.java | 13 ++++++++++--- src/main/resources/public/assets/alex.png | Bin 0 -> 3420 bytes src/main/resources/public/assets/steve.png | Bin 0 -> 1350 bytes 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/public/assets/alex.png create mode 100644 src/main/resources/public/assets/steve.png diff --git a/src/main/java/cc/fascinated/common/WebRequest.java b/src/main/java/cc/fascinated/common/WebRequest.java index c6bd3fd..b1fdbae 100644 --- a/src/main/java/cc/fascinated/common/WebRequest.java +++ b/src/main/java/cc/fascinated/common/WebRequest.java @@ -32,19 +32,19 @@ public class WebRequest { * @param the type of the response */ public static T getAsEntity(String url, Class clazz) throws RateLimitException { - ResponseEntity profile = CLIENT.get() + ResponseEntity responseEntity = CLIENT.get() .uri(url) .retrieve() .onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error .toEntity(clazz); - if (profile.getStatusCode().isError()) { + if (responseEntity.getStatusCode().isError()) { return null; } - if (profile.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) { + if (responseEntity.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) { throw new RateLimitException("Rate limit reached"); } - return profile.getBody(); + return responseEntity.getBody(); } /** diff --git a/src/main/java/cc/fascinated/model/skin/Skin.java b/src/main/java/cc/fascinated/model/skin/Skin.java index 7ef0623..5d2b30a 100644 --- a/src/main/java/cc/fascinated/model/skin/Skin.java +++ b/src/main/java/cc/fascinated/model/skin/Skin.java @@ -21,10 +21,14 @@ import java.util.Map; @Getter @Log4j2 public class Skin { /** - * The default skin, usually used when the skin is not found. + * The default skins, usually used when the skin is not found. */ - public static final Skin DEFAULT_SKIN = new Skin("http://textures.minecraft.net/texture/60a5bd016b3c9a1b9272e4929e30827a67be4ebb219017adbbc4a4d22ebd5b1", - Model.DEFAULT); + public static final Map DEFAULT_SKINS = new HashMap<>(); + + static { + DEFAULT_SKINS.put(Model.DEFAULT, new Skin(Config.INSTANCE.getWebPublicUrl() + "/assets/steve.png", Model.DEFAULT)); + DEFAULT_SKINS.put(Model.SLIM, new Skin(Config.INSTANCE.getWebPublicUrl() + "/assets/alex.png", Model.SLIM)); + } /** * The URL for the skin @@ -58,6 +62,9 @@ public class Skin { this.model = model; this.skinImage = PlayerUtils.getSkinImage(url); + if (skinImage == null) { // Use the default skin if the skin is not found + this.skinImage = PlayerUtils.getSkinImage(DEFAULT_SKINS.get(model).getUrl()); + } if (this.skinImage != null) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(this.skinImage)); diff --git a/src/main/resources/public/assets/alex.png b/src/main/resources/public/assets/alex.png new file mode 100644 index 0000000000000000000000000000000000000000..b643fe2d083f64677a630087ba4c4004eac1ca06 GIT binary patch literal 3420 zcmV-i4WsgjP)Px#24YJ`L;#EcxB!Yvbt8HJ000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i^!2 z4I~Ks0H!ej000(gR9JLFZ*6U5ZgcGub@&yq{VgycsJMh@o?as}kck@S2_ss0>J$Ekx>8h=s znV#wH@B2Nv``5h!hDe7u&MyN1`uc%r7=i1)e&qA{LBF5&)Q1AKtqxrIB(y91{Gq;Yk#kP ze&C&N6!#6Q`p}SXM8hzw0tL$madYC>9DFX93;Zex8Fh-OFw6o4%Ls9E;#eGfE}ISf zDhU}q0SvH@5KW0tNmvDpd18QlglMYUzFB|!q2auwSz?v+nMSDBK0M|eXqHqZeWnr7 zYwsIl0$lrN>TXyC{w%5|$6f6~xP+who?ieEPb9{MfT*4XQEaOAk{kfvSIj^JF!PFe1AILXcH)sK8W>_26b^5kUuHH<9Gin=K-qZDb7mF;%nMk~ z>Z?_TXc(d-gJklsqA`KlG;u5rk^yDoJgD&0T(?84vm}P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