Skip to content

Commit 2062f09

Browse files
committed
Fix skull cache handling for missing UUID profiles
Credits BlvckBytes
1 parent e5e5c92 commit 2062f09

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

SimpleAPI/src/main/java/com/bencodez/simpleapi/skull/SkullCache.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ public static String getContent(String link) throws IOException {
195195
try {
196196
URL url = new URL(link);
197197
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
198+
199+
// The UUID of this profile does not exist
200+
if (conn.getResponseCode() == 204) {
201+
return null;
202+
}
203+
198204
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
199205
String outputLine = "";
200206

@@ -214,6 +220,11 @@ public static String getContent(String link) throws IOException {
214220
@SuppressWarnings("deprecation")
215221
public static String getSkinUrl(String uuid) throws IOException {
216222
String json = getContent(api_profile_link + uuid);
223+
224+
if (json == null) {
225+
return null;
226+
}
227+
217228
JsonObject o = parser.parse(json).getAsJsonObject();
218229
String jsonBase64 = o.get("properties").getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString();
219230

@@ -270,7 +281,7 @@ public static ItemStack getSkull(String url, UUID uuid) throws MalformedURLExcep
270281
}
271282
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
272283
PlayerProfile profile = Bukkit.getServer().createPlayerProfile(uuid);
273-
profile.getTextures().setSkin(new URL(getSkinUrl(uuid.toString())));
284+
profile.getTextures().setSkin(new URL(url));
274285
skullMeta.setOwnerProfile(profile);
275286
skull.setItemMeta(skullMeta);
276287
return skull;

0 commit comments

Comments
 (0)