fix issue if bad part name is given it shows the default head
Some checks failed
deploy / deploy (push) Failing after 35s
Some checks failed
deploy / deploy (push) Failing after 35s
This commit is contained in:
parent
88da585d47
commit
6144a2e1f6
@ -2,6 +2,7 @@ package cc.fascinated.controller;
|
|||||||
|
|
||||||
import cc.fascinated.model.player.Player;
|
import cc.fascinated.model.player.Player;
|
||||||
import cc.fascinated.model.player.Skin;
|
import cc.fascinated.model.player.Skin;
|
||||||
|
import cc.fascinated.model.response.impl.InvalidPartResponse;
|
||||||
import cc.fascinated.model.response.impl.PlayerNotFoundResponse;
|
import cc.fascinated.model.response.impl.PlayerNotFoundResponse;
|
||||||
import cc.fascinated.service.PlayerService;
|
import cc.fascinated.service.PlayerService;
|
||||||
import cc.fascinated.util.PlayerUtils;
|
import cc.fascinated.util.PlayerUtils;
|
||||||
@ -39,7 +40,7 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/{part}/{id}")
|
@GetMapping(value = "/{part}/{id}")
|
||||||
public ResponseEntity<byte[]> getPlayerHead(@PathVariable String part,
|
public ResponseEntity<?> getPlayerHead(@PathVariable String part,
|
||||||
@PathVariable String id,
|
@PathVariable String id,
|
||||||
@RequestParam(required = false, defaultValue = "250") int size) {
|
@RequestParam(required = false, defaultValue = "250") int size) {
|
||||||
Player player = playerManagerService.getPlayer(id);
|
Player player = playerManagerService.getPlayer(id);
|
||||||
@ -47,9 +48,10 @@ public class PlayerController {
|
|||||||
if (player != null) { // The player exists
|
if (player != null) { // The player exists
|
||||||
Skin skin = player.getSkin();
|
Skin skin = player.getSkin();
|
||||||
Skin.Parts skinPart = Skin.Parts.fromName(part);
|
Skin.Parts skinPart = Skin.Parts.fromName(part);
|
||||||
if (skinPart != null) { // The part exists
|
if (skinPart == null) { // Unknown part name
|
||||||
partBytes = PlayerUtils.getSkinPartBytes(skin, skinPart, size);
|
return new InvalidPartResponse().toResponseEntity();
|
||||||
}
|
}
|
||||||
|
partBytes = PlayerUtils.getSkinPartBytes(skin, skinPart, size);
|
||||||
}
|
}
|
||||||
if (partBytes == null) { // Fallback to the default head
|
if (partBytes == null) { // Fallback to the default head
|
||||||
partBytes = PlayerUtils.getSkinPartBytes(Skin.DEFAULT_SKIN, Skin.Parts.HEAD, size);
|
partBytes = PlayerUtils.getSkinPartBytes(Skin.DEFAULT_SKIN, Skin.Parts.HEAD, size);
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package cc.fascinated.model.response.impl;
|
||||||
|
|
||||||
|
import cc.fascinated.model.response.Response;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
public class InvalidPartResponse extends Response {
|
||||||
|
|
||||||
|
public InvalidPartResponse() {
|
||||||
|
super(HttpStatus.NOT_FOUND, "Invalid part name.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user