Fixed account selection being reset (or not reset) sometimes

This commit is contained in:
RaphiMC 2023-01-10 22:39:48 +01:00
parent 4a78b4becb
commit 8d10f9956d
3 changed files with 17 additions and 6 deletions

View file

@ -17,8 +17,8 @@ public class ViaProxyUI extends JFrame {
private final JTabbedPane contentPane = new JTabbedPane();
private final List<AUITab> tabs = new ArrayList<>();
private final GeneralTab generalTab = new GeneralTab(this);
private final AccountsTab accountsTab = new AccountsTab(this);
public final GeneralTab generalTab = new GeneralTab(this);
public final AccountsTab accountsTab = new AccountsTab(this);
private ImageIcon icon;

View file

@ -9,7 +9,10 @@ import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.TimeoutException;
public class AccountsTab extends AUITab {
@ -213,8 +216,8 @@ public class AccountsTab extends AUITab {
else model.addElement(account.name() + " (Microsoft)");
}
private void markSelected(final int index) {
if (index == -1) {
public void markSelected(final int index) {
if (index < 0 || index >= this.accountsList.getModel().getSize()) {
Options.MC_ACCOUNT = null;
return;
}

View file

@ -166,7 +166,15 @@ public class GeneralTab extends AUITab {
Options.PROTOCOL_VERSION = serverVersion;
Options.BETACRAFT_AUTH = betaCraftAuth;
if (authMethod == 2) Options.OPENAUTHMOD_AUTH = true;
if (authMethod != 1) {
Options.MC_ACCOUNT = null;
} else if (Options.MC_ACCOUNT == null) {
this.frame.accountsTab.markSelected(0);
}
if (authMethod == 2) {
Options.OPENAUTHMOD_AUTH = true;
}
} catch (Throwable e) {
SwingUtilities.invokeLater(() -> {
this.frame.showError("Invalid server address!");