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}")
|
@GetMapping("/{query}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<CachedPlayer> getPlayer(@PathVariable @NonNull String query)
|
public ResponseEntity<CachedPlayer> getPlayer(@PathVariable @NonNull String query)
|
||||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
|
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
|
||||||
{
|
|
||||||
return ResponseEntity.ofNullable(mojangService.getPlayer(query, false));
|
return ResponseEntity.ofNullable(mojangService.getPlayer(query, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ public final class PlayerController {
|
|||||||
@GetMapping("/{partName}/{query}.{extension}")
|
@GetMapping("/{partName}/{query}.{extension}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<byte[]> getPartTexture(@PathVariable @NonNull String partName, @PathVariable @NonNull String query,
|
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 {
|
) throws BadRequestException {
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG)
|
.contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG)
|
||||||
|
@ -139,17 +139,24 @@ public final class MojangService {
|
|||||||
* Get the part of a skin texture for
|
* Get the part of a skin texture for
|
||||||
* a player by their username or UUID.
|
* a player by their username or UUID.
|
||||||
*
|
*
|
||||||
* @param partName the part of the player's skin texture to get
|
* @param partName the part of the player's skin texture to get
|
||||||
* @param query the query to search for the player by
|
* @param query the query to search for the player by
|
||||||
* @param extension the skin part image extension
|
* @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
|
* @return the skin part texture
|
||||||
* @throws BadRequestException if the extension is invalid
|
* @throws BadRequestException if the extension is invalid
|
||||||
* @throws MojangRateLimitException if the Mojang API rate limit is reached
|
* @throws MojangRateLimitException if the Mojang API rate limit is reached
|
||||||
*/
|
*/
|
||||||
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, Integer size)
|
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, String sizeString)
|
||||||
throws BadRequestException, MojangRateLimitException
|
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
|
Skin.Part part = EnumUtils.getEnumConstant(Skin.Part.class, partName.toUpperCase()); // The skin part to get
|
||||||
if (part == null) { // Default to the head part
|
if (part == null) { // Default to the head part
|
||||||
part = Skin.Part.HEAD;
|
part = Skin.Part.HEAD;
|
||||||
@ -189,12 +196,11 @@ public final class MojangService {
|
|||||||
* @return the player
|
* @return the player
|
||||||
* @throws BadRequestException if the UUID or username is invalid
|
* @throws BadRequestException if the UUID or username is invalid
|
||||||
* @throws ResourceNotFoundException if the player is not found
|
* @throws ResourceNotFoundException if the player is not found
|
||||||
* @throws MojangRateLimitException if the Mojang API rate limit is reached
|
* @throws MojangRateLimitException if the Mojang API rate limit is reached
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public CachedPlayer getPlayer(@NonNull String query, boolean bypassCache)
|
public CachedPlayer getPlayer(@NonNull String query, boolean bypassCache)
|
||||||
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
|
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
|
||||||
{
|
|
||||||
log.info("Requesting player with query: {}", query);
|
log.info("Requesting player with query: {}", query);
|
||||||
|
|
||||||
UUID uuid; // The player UUID to lookup
|
UUID uuid; // The player UUID to lookup
|
||||||
@ -390,7 +396,7 @@ public final class MojangService {
|
|||||||
* @param username the player's username
|
* @param username the player's username
|
||||||
* @return the player's UUID
|
* @return the player's UUID
|
||||||
* @throws ResourceNotFoundException if the player isn't found
|
* @throws ResourceNotFoundException if the player isn't found
|
||||||
* @throws MojangRateLimitException if the Mojang rate limit is reached
|
* @throws MojangRateLimitException if the Mojang rate limit is reached
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private UUID usernameToUUID(@NonNull String username) throws ResourceNotFoundException, MojangRateLimitException {
|
private UUID usernameToUUID(@NonNull String username) throws ResourceNotFoundException, MojangRateLimitException {
|
||||||
|
Loading…
Reference in New Issue
Block a user