修复无法显示未设置皮肤的Yggdrasil账户的皮肤的问题

This commit is contained in:
yushijinhun
2018-06-02 19:21:41 +08:00
parent 3866377a28
commit bbe584bd91
4 changed files with 12 additions and 12 deletions

View File

@@ -83,9 +83,11 @@ public final class AccountHelper {
} }
public static Image getSkin(YggdrasilAccount account, double scaleRatio) { public static Image getSkin(YggdrasilAccount account, double scaleRatio) {
if (account.getCharacter() == null) UUID uuid = account.getUUID();
return getDefaultSkin(account, scaleRatio); if (uuid == null)
File file = getSkinFile(account.getUUID()); return getSteveSkin(scaleRatio);
File file = getSkinFile(uuid);
if (file.exists()) { if (file.exists()) {
Image original = new Image("file:" + file.getAbsolutePath()); Image original = new Image("file:" + file.getAbsolutePath());
return new Image("file:" + file.getAbsolutePath(), return new Image("file:" + file.getAbsolutePath(),
@@ -93,14 +95,14 @@ public final class AccountHelper {
original.getHeight() * scaleRatio, original.getHeight() * scaleRatio,
false, false); false, false);
} }
return getDefaultSkin(account, scaleRatio); return getDefaultSkin(uuid, scaleRatio);
} }
public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio, Proxy proxy) throws Exception { public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio, Proxy proxy) throws Exception {
File file = getSkinFile(profile.getId()); File file = getSkinFile(profile.getId());
downloadSkin(account, profile, true, proxy); downloadSkin(account, profile, true, proxy);
if (!file.exists()) if (!file.exists())
return getDefaultSkin(account, scaleRatio); return getDefaultSkin(profile.getId(), scaleRatio);
String url = "file:" + file.getAbsolutePath(); String url = "file:" + file.getAbsolutePath();
return scale(url, scaleRatio); return scale(url, scaleRatio);
@@ -187,11 +189,8 @@ public final class AccountHelper {
return scale("/assets/img/alex.png", 4); return scale("/assets/img/alex.png", 4);
} }
public static Image getDefaultSkin(Account account, double scaleRatio) { public static Image getDefaultSkin(UUID uuid, double scaleRatio) {
if (account == null) int type = uuid.hashCode() & 1;
return getSteveSkin(scaleRatio);
int type = account.getUUID().hashCode() & 1;
if (type == 1) if (type == 1)
return getAlexSkin(scaleRatio); return getAlexSkin(scaleRatio);
else else

View File

@@ -208,6 +208,7 @@ public class AddAccountPane extends StackPane {
try { try {
image = AccountHelper.getSkinImmediately(yggdrasilAccount, profile, 4, Settings.INSTANCE.getProxy()); image = AccountHelper.getSkinImmediately(yggdrasilAccount, profile, 4, Settings.INSTANCE.getProxy());
} catch (Exception e) { } catch (Exception e) {
Logging.LOG.log(Level.WARNING, "Failed to get skin for " + profile.getName(), e);
image = FXUtils.DEFAULT_ICON; image = FXUtils.DEFAULT_ICON;
} }
ImageView portraitView = new ImageView(); ImageView portraitView = new ImageView();

View File

@@ -167,7 +167,7 @@ public final class LeftPaneController {
Image image = AccountHelper.getSkin((YggdrasilAccount) account, 4); Image image = AccountHelper.getSkin((YggdrasilAccount) account, 4);
item.setImage(image, AccountHelper.getViewport(4)); item.setImage(image, AccountHelper.getViewport(4));
} else } else
item.setImage(AccountHelper.getDefaultSkin(account, 4), AccountHelper.getViewport(4)); item.setImage(AccountHelper.getDefaultSkin(account.getUUID(), 4), AccountHelper.getViewport(4));
if (account instanceof AuthlibInjectorAccount) if (account instanceof AuthlibInjectorAccount)
Accounts.getAuthlibInjectorServerNameAsync((AuthlibInjectorAccount) account) Accounts.getAuthlibInjectorServerNameAsync((AuthlibInjectorAccount) account)

View File

@@ -145,7 +145,7 @@ public class YggdrasilAccount extends Account {
} }
public UUID getUUID() { public UUID getUUID() {
if (session == null) if (session == null || session.getSelectedProfile() == null)
return null; return null;
else else
return session.getSelectedProfile().getId(); return session.getSelectedProfile().getId();