From 0e97e5233762be5406fd6e819cb2de47e15c192b Mon Sep 17 00:00:00 2001 From: Tim203 Date: Thu, 10 Oct 2019 23:27:30 +0200 Subject: [PATCH] Only notify debuggers that parsing GameProfile data failed and use the default skin and cape --- .../geysermc/connector/utils/SkinUtils.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index 7254637a..1202b4df 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -67,23 +67,29 @@ public class SkinUtils { private boolean alex; public static GameProfileData from(GameProfile profile) { - GameProfile.Property skinProperty = profile.getProperty("textures"); + try { + GameProfile.Property skinProperty = profile.getProperty("textures"); - JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), Charsets.UTF_8), JsonObject.class); - JsonObject textures = skinObject.getAsJsonObject("textures"); + JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), Charsets.UTF_8), JsonObject.class); + JsonObject textures = skinObject.getAsJsonObject("textures"); - JsonObject skinTexture = textures.getAsJsonObject("SKIN"); - String skinUrl = skinTexture.get("url").getAsString(); + JsonObject skinTexture = textures.getAsJsonObject("SKIN"); + String skinUrl = skinTexture.get("url").getAsString(); - boolean isAlex = skinTexture.has("metadata"); + boolean isAlex = skinTexture.has("metadata"); - String capeUrl = null; - if (textures.has("CAPE")) { - JsonObject capeTexture = textures.getAsJsonObject("CAPE"); - capeUrl = capeTexture.get("url").getAsString(); + String capeUrl = null; + if (textures.has("CAPE")) { + JsonObject capeTexture = textures.getAsJsonObject("CAPE"); + capeUrl = capeTexture.get("url").getAsString(); + } + + return new GameProfileData(skinUrl, capeUrl, isAlex); + } catch (Exception exception) { + // return default skin with default cape when texture data is invalid + Geyser.getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); + return new GameProfileData("", "", false); } - - return new GameProfileData(skinUrl, capeUrl, isAlex); } }