Skip to content

Commit

Permalink
Move image download function to new MCUtils lib
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed May 6, 2023
1 parent 428947d commit fb7c4d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
<version>v2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.TechnicJelle</groupId>
<artifactId>MCUtils</artifactId>
<version>v1.0</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.technicjelle.MCUtils;
import com.technicjelle.UpdateChecker;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.plugin.SkinProvider;
Expand All @@ -11,7 +12,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -140,31 +140,7 @@ private long getXuid(UUID playerUUID) {
* @return the skin of the player, or null if it could not be found
*/
private @Nullable BufferedImage skinFromTextureID(@NotNull String textureID) {
verboseLog("Getting skin from textureID: " + textureID);
return imageFromURL("https://textures.minecraft.net/texture/" + textureID);
}

/**
* @param url URL of the image
* @return the image, or null if it could not be found
*/
private @Nullable BufferedImage imageFromURL(@NotNull String url) {
BufferedImage result;
try {
URL imageUrl = new URL(url);
verboseLog("Getting image from URL: " + url);
try {
InputStream in = imageUrl.openStream();
result = ImageIO.read(in);
in.close();
} catch (IOException e) {
getLogger().log(Level.SEVERE, "Failed to get the image from " + url, e);
return null;
}
} catch (MalformedURLException e) {
getLogger().log(Level.SEVERE, "URL is malformed: " + url, e);
return null;
}
return result;
verboseLog("Downloading skin with textureID: " + textureID);
return MCUtils.downloadImage("https://textures.minecraft.net/texture/" + textureID);
}
}

0 comments on commit fb7c4d9

Please sign in to comment.