cleanup
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m27s

This commit is contained in:
Lee 2024-04-12 18:56:25 +01:00
parent e788ae003f
commit 4e08955ab9
3 changed files with 11 additions and 11 deletions

View File

@ -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);
}
}
}

View File

@ -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) {}
}
}

View File

@ -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<CachedPlayerSkinPart> 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;