Skip to content

Commit

Permalink
handle the url connection separately from everything else, closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Dec 26, 2023
1 parent 86b7f76 commit 6e0c4e8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/src/main/java/net/pl3x/map/core/player/PlayerTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import javax.imageio.ImageIO;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.util.Colors;
import net.pl3x.map.core.util.FileUtil;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -72,8 +74,17 @@ public void run() {
if (this.url == null) {
return;
}

InputStream inputStream = null;
try {
inputStream = this.url.openStream();
} catch (IOException e) {
Logger.warn("Failed to get texture of %s from %s: %s".formatted(this.uuid, this.url, e.getCause()), e);
return;
}

try {
BufferedImage textureSource = ImageIO.read(this.url);
BufferedImage textureSource = ImageIO.read(inputStream);

BufferedImage head2D = get2DHead(textureSource);
ImageIO.write(head2D, "png", SKINS_2D_DIR.resolve(this.uuid + ".png").toFile());
Expand All @@ -88,7 +99,7 @@ public void run() {
}
ImageIO.write(head3D, "png", SKINS_3D_DIR.resolve(this.uuid + ".png").toFile());
} catch (Throwable t) {
t.printStackTrace();
Logger.warn("Failed to process player texture with uuid of %s".formatted(this.uuid), t);
}
}

Expand Down

0 comments on commit 6e0c4e8

Please sign in to comment.