Catch exceptions during skin request

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-01 22:53:46 +02:00
parent 3674fcc97d
commit 446e4a64b7

View File

@ -26,6 +26,7 @@ public record PlayerSkin(String textures, String signature) {
public static @Nullable PlayerSkin fromUuid(@NotNull String uuid) { public static @Nullable PlayerSkin fromUuid(@NotNull String uuid) {
final JsonObject jsonObject = MojangUtils.fromUuid(uuid); final JsonObject jsonObject = MojangUtils.fromUuid(uuid);
if (jsonObject == null) return null; if (jsonObject == null) return null;
try {
final JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray(); final JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray();
for (JsonElement jsonElement : propertiesArray) { for (JsonElement jsonElement : propertiesArray) {
final JsonObject propertyObject = jsonElement.getAsJsonObject(); final JsonObject propertyObject = jsonElement.getAsJsonObject();
@ -36,6 +37,9 @@ public record PlayerSkin(String textures, String signature) {
return new PlayerSkin(textureValue, signatureValue); return new PlayerSkin(textureValue, signatureValue);
} }
return null; return null;
} catch (Exception e) {
return null;
}
} }
/** /**
@ -48,9 +52,13 @@ public record PlayerSkin(String textures, String signature) {
public static @Nullable PlayerSkin fromUsername(@NotNull String username) { public static @Nullable PlayerSkin fromUsername(@NotNull String username) {
final JsonObject jsonObject = MojangUtils.fromUsername(username); final JsonObject jsonObject = MojangUtils.fromUsername(username);
if (jsonObject == null) return null; if (jsonObject == null) return null;
try {
final String uuid = jsonObject.get("id").getAsString(); final String uuid = jsonObject.get("id").getAsString();
// Retrieve the skin data from the mojang uuid // Retrieve the skin data from the mojang uuid
return fromUuid(uuid); return fromUuid(uuid);
} catch (Exception e) {
return null;
}
} }
/** /**