cache the skin image not the skin image bytes
This commit is contained in:
parent
d3adb6815d
commit
d5fc5c0a8c
@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,19 +21,19 @@ public class Skin {
|
||||
Model.DEFAULT);
|
||||
|
||||
/**
|
||||
* The URL of the skin
|
||||
* The URL for the skin
|
||||
*/
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* The model of the skin
|
||||
* The model for the skin
|
||||
*/
|
||||
private final Model model;
|
||||
|
||||
/**
|
||||
* The skin data of the skin
|
||||
* The skin image for the skin
|
||||
*/
|
||||
private final byte[] skinData;
|
||||
private final BufferedImage skinImage;
|
||||
|
||||
/**
|
||||
* The part URLs of the skin
|
||||
@ -44,7 +45,7 @@ public class Skin {
|
||||
this.url = url;
|
||||
this.model = model;
|
||||
|
||||
this.skinData = PlayerUtils.getSkinData(url);
|
||||
this.skinImage = PlayerUtils.getSkinImage(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,13 +26,17 @@ public class PlayerUtils {
|
||||
*/
|
||||
@SneakyThrows
|
||||
@JsonIgnore
|
||||
public static byte[] getSkinData(String url) {
|
||||
public static BufferedImage getSkinImage(String url) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(new URI(url))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
return Main.HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofByteArray()).body();
|
||||
byte[] body = Main.HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofByteArray()).body();
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
return ImageIO.read(new ByteArrayInputStream(body));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,7 +50,7 @@ public class PlayerUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(skin.getSkinData()));
|
||||
BufferedImage image = skin.getSkinImage();
|
||||
if (image == null) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user