add fallback skins
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 22s
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 22s
This commit is contained in:
parent
852f5a8bea
commit
3cf16bd2eb
@ -32,19 +32,19 @@ public class WebRequest {
|
||||
* @param <T> the type of the response
|
||||
*/
|
||||
public static <T> T getAsEntity(String url, Class<T> clazz) throws RateLimitException {
|
||||
ResponseEntity<T> profile = CLIENT.get()
|
||||
ResponseEntity<T> responseEntity = CLIENT.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.onStatus(HttpStatusCode::isError, (request, response) -> {}) // Don't throw exceptions on error
|
||||
.toEntity(clazz);
|
||||
|
||||
if (profile.getStatusCode().isError()) {
|
||||
if (responseEntity.getStatusCode().isError()) {
|
||||
return null;
|
||||
}
|
||||
if (profile.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) {
|
||||
if (responseEntity.getStatusCode().isSameCodeAs(HttpStatus.TOO_MANY_REQUESTS)) {
|
||||
throw new RateLimitException("Rate limit reached");
|
||||
}
|
||||
return profile.getBody();
|
||||
return responseEntity.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,10 +21,14 @@ import java.util.Map;
|
||||
@Getter @Log4j2
|
||||
public class Skin {
|
||||
/**
|
||||
* The default skin, usually used when the skin is not found.
|
||||
* The default skins, usually used when the skin is not found.
|
||||
*/
|
||||
public static final Skin DEFAULT_SKIN = new Skin("http://textures.minecraft.net/texture/60a5bd016b3c9a1b9272e4929e30827a67be4ebb219017adbbc4a4d22ebd5b1",
|
||||
Model.DEFAULT);
|
||||
public static final Map<Model, Skin> DEFAULT_SKINS = new HashMap<>();
|
||||
|
||||
static {
|
||||
DEFAULT_SKINS.put(Model.DEFAULT, new Skin(Config.INSTANCE.getWebPublicUrl() + "/assets/steve.png", Model.DEFAULT));
|
||||
DEFAULT_SKINS.put(Model.SLIM, new Skin(Config.INSTANCE.getWebPublicUrl() + "/assets/alex.png", Model.SLIM));
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL for the skin
|
||||
@ -58,6 +62,9 @@ public class Skin {
|
||||
this.model = model;
|
||||
|
||||
this.skinImage = PlayerUtils.getSkinImage(url);
|
||||
if (skinImage == null) { // Use the default skin if the skin is not found
|
||||
this.skinImage = PlayerUtils.getSkinImage(DEFAULT_SKINS.get(model).getUrl());
|
||||
}
|
||||
if (this.skinImage != null) {
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(this.skinImage));
|
||||
|
BIN
src/main/resources/public/assets/alex.png
Normal file
BIN
src/main/resources/public/assets/alex.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
src/main/resources/public/assets/steve.png
Normal file
BIN
src/main/resources/public/assets/steve.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user