Handle invalid size params for player skin parts
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0) (push) Successful in 1m5s
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0) (push) Successful in 1m5s
This commit is contained in:
parent
32c93b5e58
commit
ec69120a26
@ -68,8 +68,7 @@ public final class PlayerController {
|
||||
@GetMapping("/{query}")
|
||||
@ResponseBody
|
||||
public ResponseEntity<CachedPlayer> getPlayer(@PathVariable @NonNull String query)
|
||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
|
||||
{
|
||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
|
||||
return ResponseEntity.ofNullable(mojangService.getPlayer(query, false));
|
||||
}
|
||||
|
||||
@ -92,7 +91,7 @@ public final class PlayerController {
|
||||
@GetMapping("/{partName}/{query}.{extension}")
|
||||
@ResponseBody
|
||||
public ResponseEntity<byte[]> getPartTexture(@PathVariable @NonNull String partName, @PathVariable @NonNull String query,
|
||||
@PathVariable @NonNull String extension, @RequestParam(required = false) Integer size
|
||||
@PathVariable @NonNull String extension, @RequestParam(required = false) String size
|
||||
) throws BadRequestException {
|
||||
return ResponseEntity.ok()
|
||||
.contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG)
|
||||
|
@ -142,14 +142,21 @@ public final class MojangService {
|
||||
* @param partName the part of the player's skin texture to get
|
||||
* @param query the query to search for the player by
|
||||
* @param extension the skin part image extension
|
||||
* @param size the size of the skin part image
|
||||
* @param sizeString the size of the skin part image
|
||||
* @return the skin part texture
|
||||
* @throws BadRequestException if the extension is invalid
|
||||
* @throws MojangRateLimitException if the Mojang API rate limit is reached
|
||||
*/
|
||||
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, Integer size)
|
||||
throws BadRequestException, MojangRateLimitException
|
||||
{
|
||||
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, String sizeString)
|
||||
throws BadRequestException, MojangRateLimitException {
|
||||
Integer size = null;
|
||||
if (sizeString != null) { // Attempt to parse the size
|
||||
try {
|
||||
size = Integer.parseInt(sizeString);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Safely ignore, invalid number provided
|
||||
}
|
||||
}
|
||||
Skin.Part part = EnumUtils.getEnumConstant(Skin.Part.class, partName.toUpperCase()); // The skin part to get
|
||||
if (part == null) { // Default to the head part
|
||||
part = Skin.Part.HEAD;
|
||||
@ -193,8 +200,7 @@ public final class MojangService {
|
||||
*/
|
||||
@NonNull
|
||||
public CachedPlayer getPlayer(@NonNull String query, boolean bypassCache)
|
||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
|
||||
{
|
||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
|
||||
log.info("Requesting player with query: {}", query);
|
||||
|
||||
UUID uuid; // The player UUID to lookup
|
||||
|
Loading…
Reference in New Issue
Block a user