From 1dc22f4ed464632b0790cd4adc94bb667e806832 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Sun, 26 Aug 2018 18:31:02 -0400 Subject: [PATCH] Fix console spam when server sends a broken texture profile. --- .../voxelmodpack/hdskins/HDSkinManager.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java index 7f952fe7..528321eb 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -124,26 +124,34 @@ public final class HDSkinManager implements IResourceManagerReloadListener { } public CompletableFuture> loadProfileTextures(GameProfile profile) { - // try to recreate a broken gameprofile - // happens when server sends a random profile with skin and displayname - Property textures = Iterables.getFirst(profile.getProperties().get("textures"), null); - if (textures != null) { - String json = new String(Base64.getDecoder().decode(textures.getValue()), StandardCharsets.UTF_8); - MinecraftTexturesPayload texturePayload = SkinServer.gson.fromJson(json, MinecraftTexturesPayload.class); - if (texturePayload != null) { - // name is optional - String name = texturePayload.getProfileName(); - UUID uuid = texturePayload.getProfileId(); - // uuid is required - if (uuid != null) { - profile = new GameProfile(uuid, name); - } + try { + // try to recreate a broken gameprofile + // happens when server sends a random profile with skin and displayname + Property textures = Iterables.getFirst(profile.getProperties().get("textures"), null); + if (textures != null) { + String json = new String(Base64.getDecoder().decode(textures.getValue()), StandardCharsets.UTF_8); + MinecraftTexturesPayload texturePayload = SkinServer.gson.fromJson(json, MinecraftTexturesPayload.class); + if (texturePayload != null) { + // name is optional + String name = texturePayload.getProfileName(); + UUID uuid = texturePayload.getProfileId(); + // uuid is required + if (uuid != null) { + profile = new GameProfile(uuid, name); + } - // probably uses this texture for a reason. Don't mess with it. - if (!texturePayload.getTextures().isEmpty() && texturePayload.getProfileId() == null) { - return CompletableFuture.completedFuture(Collections.emptyMap()); + // probably uses this texture for a reason. Don't mess with it. + if (!texturePayload.getTextures().isEmpty() && texturePayload.getProfileId() == null) { + return CompletableFuture.completedFuture(Collections.emptyMap()); + } } } + } catch (Exception e) { + if (profile.getId() == null) { + // Something broke server-side probably + logger.warn("{} had a null UUID and was unable to recreate it from texture profile.", profile.getName(), e); + return CompletableFuture.completedFuture(Collections.emptyMap()); + } } return skins.getUnchecked(profile); }