Fixed realms not working if the account is not refreshed

This commit is contained in:
RaphiMC 2023-11-21 00:22:45 +01:00
parent 232168873c
commit a612960655
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
3 changed files with 32 additions and 11 deletions

View File

@ -42,6 +42,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class RealmsTab extends AUITab {
@ -100,14 +101,28 @@ public class RealmsTab extends AUITab {
if (this.currentAccount == null) {
statusLabel.setText(I18n.get("tab.realms.no_account"));
} else if (this.currentAccount instanceof MicrosoftAccount account) {
final JavaRealmsService realmsService = new JavaRealmsService(HTTP_CLIENT, Iterables.getLast(this.currentSelectedJavaVersion.getProtocol().getIncludedVersions()), account.getMcProfile());
this.loadRealms(realmsService, body, statusLabel);
} else if (this.currentAccount instanceof BedrockAccount account) {
final BedrockRealmsService realmsService = new BedrockRealmsService(HTTP_CLIENT, ProtocolConstants.BEDROCK_VERSION_NAME, account.getRealmsXsts());
this.loadRealms(realmsService, body, statusLabel);
} else {
statusLabel.setText(I18n.get("tab.realms.unsupported_account"));
statusLabel.setText(I18n.get("tab.realms.refreshing_account"));
CompletableFuture.runAsync(() -> {
try {
ViaProxy.getSaveManager().accountsSave.ensureRefreshed(this.currentAccount);
SwingUtilities.invokeLater(() -> {
if (this.currentAccount instanceof MicrosoftAccount account) {
final JavaRealmsService realmsService = new JavaRealmsService(HTTP_CLIENT, Iterables.getLast(this.currentSelectedJavaVersion.getProtocol().getIncludedVersions()), account.getMcProfile());
this.loadRealms(realmsService, body, statusLabel);
} else if (this.currentAccount instanceof BedrockAccount account) {
final BedrockRealmsService realmsService = new BedrockRealmsService(HTTP_CLIENT, ProtocolConstants.BEDROCK_VERSION_NAME, account.getRealmsXsts());
this.loadRealms(realmsService, body, statusLabel);
} else {
statusLabel.setText(I18n.get("tab.realms.unsupported_account"));
}
});
} catch (Throwable e) {
Logger.LOGGER.error("Failed to refresh account", e);
ViaProxy.getUI().showError(I18n.get("tab.realms.error_account", e.getMessage()));
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_account_label")));
}
});
}
contentPane.setLayout(new BorderLayout());
@ -142,7 +157,7 @@ public class RealmsTab extends AUITab {
final Throwable cause = e.getCause();
Logger.LOGGER.error("Failed to get realms worlds", cause);
ViaProxy.getUI().showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_label")));
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_generic_label")));
return null;
});
} else {
@ -152,7 +167,7 @@ public class RealmsTab extends AUITab {
final Throwable cause = e.getCause();
Logger.LOGGER.error("Failed to check realms availability", cause);
ViaProxy.getUI().showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_label")));
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_generic_label")));
return null;
});
}

View File

@ -77,9 +77,12 @@ tab.accounts.add.timeout=Der Login Prozess ist abgelaufen.\nBitte logge dich inn
tabs.realms.name=Realms
tab.realms.error_generic=Realms Anfrage konnte nicht verarbeitet werden: %s
tab.realms.error_label=Ein unbekannter Fehler ist aufgetreten
tab.realms.error_generic_label=Ein unbekannter Fehler ist aufgetreten
tab.realms.error_account=Das Konto konnte nicht aktualisiert werden. Das könnte durch alte Account-Tokens oder Rate-Limits verursacht sein. Warte ein paar Sekunden und probiere es dann erneut. Sollte das Problem nicht behoben sein, entferne das Konto und füge es neu hinzu.
tab.realms.error_account_label=Konto Fehler
tab.realms.no_account=Kein Konto ausgewählt
tab.realms.unsupported_account=Das ausgewählte Konto wird nicht unterstützt
tab.realms.refreshing_account=Aktualisiere Konto...
tab.realms.availability_check=Prüfe Verfügbarkeit...
tab.realms.unavailable=Deine ViaProxy ist veraltet und nicht kompatibel mit Minecraft Realms.\nBitte nutze die neuste ViaProxy Version.
tab.realms.loading_worlds=Lade Welten...

View File

@ -77,9 +77,12 @@ tab.accounts.add.timeout=The login request timed out.\nPlease login within %s se
tab.realms.name=Realms
tab.realms.error_generic=Realms request could not be handled: %s
tab.realms.error_label=An unknown error occurred
tab.realms.error_generic_label=An unknown error occurred
tab.realms.error_account=Could not refresh the selected account. This might be caused by outdated account tokens or rate limits. Wait a couple of seconds and try again. If the problem persists, remove and re-add your account.
tab.realms.error_account_label=Account error
tab.realms.no_account=No account selected
tab.realms.unsupported_account=Unsupported account selected
tab.realms.refreshing_account=Refreshing account...
tab.realms.availability_check=Checking availability...
tab.realms.unavailable=Your ViaProxy is outdated and not compatible with Minecraft Realms.\nPlease use the latest version of ViaProxy.
tab.realms.loading_worlds=Loading worlds...