Cache session profile response. Closes #280

This commit is contained in:
huanghongxun
2018-02-17 23:38:40 +08:00
parent 24ec0adacf
commit adf6c19996

View File

@@ -298,10 +298,17 @@ public class YggdrasilAccount extends Account {
if (StringUtils.isBlank(userId))
throw new IllegalStateException("Not logged in");
ProfileResponse response = GSON.fromJson(NetworkUtils.doGet(NetworkUtils.toURL(baseProfile + UUIDTypeAdapter.fromUUID(profile.getId()))), ProfileResponse.class);
if (response.getProperties() == null) return Optional.empty();
Property textureProperty = response.getProperties().get("textures");
if (textureProperty == null) return Optional.empty();
Property textureProperty;
if (getUserProperties().containsKey("textures"))
textureProperty = getUserProperties().get("textures");
else {
ProfileResponse response = GSON.fromJson(NetworkUtils.doGet(NetworkUtils.toURL(baseProfile + UUIDTypeAdapter.fromUUID(profile.getId()))), ProfileResponse.class);
if (response.getProperties() == null) return Optional.empty();
textureProperty = response.getProperties().get("textures");
if (textureProperty == null) return Optional.empty();
getUserProperties().putAll(response.getProperties());
}
TextureResponse texture;
String json = new String(Base64.getDecoder().decode(textureProperty.getValue()), Charsets.UTF_8);