forked from MinecraftUtilities/Backend
cleanup and add player skin format link
This commit is contained in:
parent
4b672de85d
commit
157bdf5e5a
@ -56,6 +56,12 @@ public interface ISkinPart {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vanilla skin parts.
|
||||||
|
* <p>
|
||||||
|
* <a href="https://cdn.fascinated.cc/sXwEKAxm.png">Skin Format</a>
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
enum Vanilla implements ISkinPart {
|
enum Vanilla implements ISkinPart {
|
||||||
// Overlays
|
// Overlays
|
||||||
|
@ -54,24 +54,23 @@ public class PlayerService {
|
|||||||
* @return the player
|
* @return the player
|
||||||
*/
|
*/
|
||||||
public CachedPlayer getPlayer(String id) {
|
public CachedPlayer getPlayer(String id) {
|
||||||
String originalId = id;
|
// Convert the id to uppercase to prevent case sensitivity
|
||||||
id = id.toUpperCase(); // Convert the id to uppercase to prevent case sensitivity
|
log.info("Getting player: {}", id);
|
||||||
log.info("Getting player: {}", originalId);
|
UUID uuid = PlayerUtils.getUuidFromString(id);
|
||||||
UUID uuid = PlayerUtils.getUuidFromString(originalId);
|
|
||||||
if (uuid == null) { // If the id is not a valid uuid, get the uuid from the username
|
if (uuid == null) { // If the id is not a valid uuid, get the uuid from the username
|
||||||
uuid = usernameToUuid(originalId).getUniqueId();
|
uuid = usernameToUuid(id).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
||||||
if (cachedPlayer.isPresent() && Config.INSTANCE.isProduction()) { // Return the cached player if it exists
|
if (cachedPlayer.isPresent() && Config.INSTANCE.isProduction()) { // Return the cached player if it exists
|
||||||
log.info("Player {} is cached", originalId);
|
log.info("Player {} is cached", id);
|
||||||
return cachedPlayer.get();
|
return cachedPlayer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("Getting player profile from Mojang: {}", originalId);
|
log.info("Getting player profile from Mojang: {}", id);
|
||||||
MojangProfile mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang
|
MojangProfile mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang
|
||||||
log.info("Got player profile from Mojang: {}", originalId);
|
log.info("Got player profile from Mojang: {}", id);
|
||||||
Tuple<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape();
|
Tuple<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape();
|
||||||
CachedPlayer player = new CachedPlayer(
|
CachedPlayer player = new CachedPlayer(
|
||||||
uuid, // Player UUID
|
uuid, // Player UUID
|
||||||
@ -136,6 +135,7 @@ public class PlayerService {
|
|||||||
log.info("Size {} is too small, setting to 32", size);
|
log.info("Size {} is too small, setting to 32", size);
|
||||||
size = 32;
|
size = 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISkinPart part = ISkinPart.getByName(partName); // The skin part to get
|
ISkinPart part = ISkinPart.getByName(partName); // The skin part to get
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
throw new BadRequestException("Invalid skin part: %s".formatted(partName));
|
throw new BadRequestException("Invalid skin part: %s".formatted(partName));
|
||||||
@ -144,6 +144,7 @@ public class PlayerService {
|
|||||||
String name = part.name();
|
String name = part.name();
|
||||||
log.info("Getting skin part {} for player: {} (size: {}, renderOverlays: {})", name, player.getUniqueId(), size, renderOverlay);
|
log.info("Getting skin part {} for player: {} (size: {}, renderOverlays: {})", name, player.getUniqueId(), size, renderOverlay);
|
||||||
String key = "%s-%s-%s-%s".formatted(player.getUniqueId(), name, size, renderOverlay);
|
String key = "%s-%s-%s-%s".formatted(player.getUniqueId(), name, size, renderOverlay);
|
||||||
|
|
||||||
Optional<CachedPlayerSkinPart> cache = playerSkinPartCacheRepository.findById(key);
|
Optional<CachedPlayerSkinPart> cache = playerSkinPartCacheRepository.findById(key);
|
||||||
|
|
||||||
// The skin part is cached
|
// The skin part is cached
|
||||||
@ -161,7 +162,6 @@ public class PlayerService {
|
|||||||
ImageUtils.imageToBytes(renderedPart)
|
ImageUtils.imageToBytes(renderedPart)
|
||||||
);
|
);
|
||||||
log.info("Fetched skin part {} for player: {}", name, player.getUniqueId());
|
log.info("Fetched skin part {} for player: {}", name, player.getUniqueId());
|
||||||
|
|
||||||
playerSkinPartCacheRepository.save(skinPart);
|
playerSkinPartCacheRepository.save(skinPart);
|
||||||
return skinPart;
|
return skinPart;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user