From 4e08955ab9841ac3f5a903be734bebb390d32ba1 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 12 Apr 2024 18:56:25 +0100 Subject: [PATCH] cleanup --- src/main/java/cc/fascinated/common/ImageUtils.java | 2 ++ src/main/java/cc/fascinated/model/skin/Skin.java | 6 ++---- .../java/cc/fascinated/service/PlayerService.java | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/cc/fascinated/common/ImageUtils.java b/src/main/java/cc/fascinated/common/ImageUtils.java index b06b436..2400fa0 100644 --- a/src/main/java/cc/fascinated/common/ImageUtils.java +++ b/src/main/java/cc/fascinated/common/ImageUtils.java @@ -52,6 +52,8 @@ public class ImageUtils { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { ImageIO.write(image, "png", outputStream); return outputStream.toByteArray(); + } catch (Exception e) { + throw new Exception("Failed to convert image to bytes", e); } } } diff --git a/src/main/java/cc/fascinated/model/skin/Skin.java b/src/main/java/cc/fascinated/model/skin/Skin.java index b0f9064..0bf93a8 100644 --- a/src/main/java/cc/fascinated/model/skin/Skin.java +++ b/src/main/java/cc/fascinated/model/skin/Skin.java @@ -38,7 +38,7 @@ public class Skin { /** * The legacy status of the skin */ - private boolean isLegacy = false; + private boolean legacy; /** * The skin image for the skin @@ -60,9 +60,7 @@ public class Skin { if (this.skinImage != null) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(this.skinImage)); - if (image.getWidth() == 64 && image.getHeight() == 32) { // Using the old skin format - this.isLegacy = true; - } + this.legacy = image.getWidth() == 64 && image.getHeight() == 32; } catch (Exception ignored) {} } } diff --git a/src/main/java/cc/fascinated/service/PlayerService.java b/src/main/java/cc/fascinated/service/PlayerService.java index 35efc13..aecbfc7 100644 --- a/src/main/java/cc/fascinated/service/PlayerService.java +++ b/src/main/java/cc/fascinated/service/PlayerService.java @@ -137,26 +137,26 @@ public class PlayerService { throw new BadRequestException("Invalid skin part: %s".formatted(partName)); } - log.info("Getting skin part {} for player: {}", part.name(), player.getUniqueId()); - String key = "%s-%s-%s-%s".formatted(player.getUniqueId(), part.name(), size, renderOverlay); + String name = part.name(); + log.info("Getting skin part {} for player: {}", name, player.getUniqueId()); + String key = "%s-%s-%s-%s".formatted(player.getUniqueId(), name, size, renderOverlay); Optional cache = playerSkinPartCacheRepository.findById(key); // The skin part is cached if (cache.isPresent() && Config.INSTANCE.isProduction()) { - log.info("Skin part {} for player {} is cached", part.name(), player.getUniqueId()); + log.info("Skin part {} for player {} is cached", name, player.getUniqueId()); return cache.get(); } long before = System.currentTimeMillis(); BufferedImage renderedPart = part.render(player.getSkin(), renderOverlay, size); // Render the skin part - log.info("Took {}ms to render skin part {} for player: {}", System.currentTimeMillis() - before, part.name(), player.getUniqueId()); + log.info("Took {}ms to render skin part {} for player: {}", System.currentTimeMillis() - before, name, player.getUniqueId()); - byte[] skinPartBytes = ImageUtils.imageToBytes(renderedPart); // Convert the image to bytes CachedPlayerSkinPart skinPart = new CachedPlayerSkinPart( key, - skinPartBytes + ImageUtils.imageToBytes(renderedPart) ); - log.info("Fetched skin part {} for player: {}", part.name(), player.getUniqueId()); + log.info("Fetched skin part {} for player: {}", name, player.getUniqueId()); playerSkinPartCacheRepository.save(skinPart); return skinPart;