Fix console spam when server sends a broken texture profile.

This commit is contained in:
Matthew Messinger 2018-08-26 18:31:02 -04:00
parent 91f741fa08
commit 1dc22f4ed4

View file

@ -124,26 +124,34 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
} }
public CompletableFuture<Map<Type, MinecraftProfileTexture>> loadProfileTextures(GameProfile profile) { public CompletableFuture<Map<Type, MinecraftProfileTexture>> loadProfileTextures(GameProfile profile) {
// try to recreate a broken gameprofile try {
// happens when server sends a random profile with skin and displayname // try to recreate a broken gameprofile
Property textures = Iterables.getFirst(profile.getProperties().get("textures"), null); // happens when server sends a random profile with skin and displayname
if (textures != null) { Property textures = Iterables.getFirst(profile.getProperties().get("textures"), null);
String json = new String(Base64.getDecoder().decode(textures.getValue()), StandardCharsets.UTF_8); if (textures != null) {
MinecraftTexturesPayload texturePayload = SkinServer.gson.fromJson(json, MinecraftTexturesPayload.class); String json = new String(Base64.getDecoder().decode(textures.getValue()), StandardCharsets.UTF_8);
if (texturePayload != null) { MinecraftTexturesPayload texturePayload = SkinServer.gson.fromJson(json, MinecraftTexturesPayload.class);
// name is optional if (texturePayload != null) {
String name = texturePayload.getProfileName(); // name is optional
UUID uuid = texturePayload.getProfileId(); String name = texturePayload.getProfileName();
// uuid is required UUID uuid = texturePayload.getProfileId();
if (uuid != null) { // uuid is required
profile = new GameProfile(uuid, name); if (uuid != null) {
} profile = new GameProfile(uuid, name);
}
// probably uses this texture for a reason. Don't mess with it. // probably uses this texture for a reason. Don't mess with it.
if (!texturePayload.getTextures().isEmpty() && texturePayload.getProfileId() == null) { if (!texturePayload.getTextures().isEmpty() && texturePayload.getProfileId() == null) {
return CompletableFuture.completedFuture(Collections.emptyMap()); 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); return skins.getUnchecked(profile);
} }