Recoded Account management

This commit is contained in:
RaphiMC 2023-02-01 22:04:02 +01:00
parent cc514685d8
commit 49cbab9685
11 changed files with 437 additions and 133 deletions

View File

@ -20,8 +20,8 @@ package net.raphimc.viaproxy.cli.options;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import net.raphimc.mcauth.step.java.StepMCProfile;
import net.raphimc.viaprotocolhack.util.VersionEnum;
import net.raphimc.viaproxy.saves.impl.accounts.Account;
import net.raphimc.viaproxy.util.logging.Logger;
import java.io.IOException;
@ -48,7 +48,7 @@ public class Options {
public static boolean BETACRAFT_AUTH;
// GUI only config options
public static StepMCProfile.MCProfile MC_ACCOUNT;
public static Account MC_ACCOUNT;
public static void parse(final String[] args) throws IOException {
final OptionParser parser = new OptionParser();

View File

@ -40,6 +40,7 @@ import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1
import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_1;
import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3;
import net.raphimc.viaproxy.proxy.ProxyConnection;
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
import net.raphimc.viaproxy.util.LocalSocketClient;
import net.raphimc.viaproxy.util.logging.Logger;
@ -82,11 +83,12 @@ public class ExternalInterface {
proxyConnection.setLoginHelloPacket(new C2SLoginHelloPacket1_19_3(name, expiresAt, publicKey, keySignature, uuid));
}
} else if (Options.MC_ACCOUNT != null) {
proxyConnection.setGameProfile(new GameProfile(Options.MC_ACCOUNT.id(), Options.MC_ACCOUNT.name()));
proxyConnection.setGameProfile(Options.MC_ACCOUNT.getGameProfile());
if (!Options.MC_ACCOUNT.prevResult().items().isEmpty() && proxyConnection.getServerVersion().isBetweenInclusive(VersionEnum.r1_19, VersionEnum.r1_19_3)) {
if (Options.MC_ACCOUNT instanceof MicrosoftAccount && proxyConnection.getServerVersion().isBetweenInclusive(VersionEnum.r1_19, VersionEnum.r1_19_3)) {
final MicrosoftAccount microsoftAccount = (MicrosoftAccount) Options.MC_ACCOUNT;
final UserConnection user = proxyConnection.getUserConnection();
final UserApiService userApiService = AuthLibServices.AUTHENTICATION_SERVICE.createUserApiService(Options.MC_ACCOUNT.prevResult().prevResult().access_token());
final UserApiService userApiService = AuthLibServices.AUTHENTICATION_SERVICE.createUserApiService(microsoftAccount.getMcProfile().prevResult().prevResult().access_token());
final KeyPairResponse keyPair = userApiService.getKeyPair();
if (keyPair != null) {
if (!Strings.isNullOrEmpty(keyPair.getPublicKey()) && keyPair.getPublicKeySignature() != null && keyPair.getPublicKeySignature().array().length != 0) {
@ -128,9 +130,10 @@ public class ExternalInterface {
}
} else if (Options.LOCAL_SOCKET_AUTH) {
new LocalSocketClient(48941).request("authenticate", serverIdHash);
} else if (Options.MC_ACCOUNT != null && !Options.MC_ACCOUNT.prevResult().items().isEmpty()) {
} else if (Options.MC_ACCOUNT instanceof MicrosoftAccount) {
final MicrosoftAccount microsoftAccount = (MicrosoftAccount) Options.MC_ACCOUNT;
try {
AuthLibServices.SESSION_SERVICE.joinServer(new GameProfile(Options.MC_ACCOUNT.id(), Options.MC_ACCOUNT.name()), Options.MC_ACCOUNT.prevResult().prevResult().access_token(), serverIdHash);
AuthLibServices.SESSION_SERVICE.joinServer(Options.MC_ACCOUNT.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
} catch (Throwable e) {
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later.");
}
@ -156,7 +159,7 @@ public class ExternalInterface {
packet.salt = Long.valueOf(response[1]);
packet.signature = Base64.getDecoder().decode(response[2]);
}
} else if (Options.MC_ACCOUNT != null && !Options.MC_ACCOUNT.prevResult().items().isEmpty()) {
} else if (Options.MC_ACCOUNT instanceof MicrosoftAccount) {
final UserConnection user = proxyConnection.getUserConnection();
final ChatSession1_19_1 chatSession = user.get(ChatSession1_19_1.class);
if (chatSession == null) return;

View File

@ -18,9 +18,10 @@
package net.raphimc.viaproxy.saves;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.saves.impl.AccountsSave;
import net.raphimc.viaproxy.saves.impl.NewAccountsSave;
import net.raphimc.viaproxy.saves.impl.UISave;
import net.raphimc.viaproxy.util.logging.Logger;
@ -33,7 +34,7 @@ public class SaveManager {
private static final File SAVE_FILE = new File("saves.json");
private static final Gson GSON = new Gson();
public final AccountsSave accountsSave = new AccountsSave();
public final NewAccountsSave accountsSave = new NewAccountsSave();
public final UISave uiSave = new UISave();
public SaveManager() {
@ -65,6 +66,8 @@ public class SaveManager {
Logger.LOGGER.error("Failed to load save " + save.getName(), e);
}
});
SaveMigrator.migrate(this, saveObject);
} catch (Throwable e) {
Logger.LOGGER.error("Failed to load saves from file", e);
}
@ -80,7 +83,10 @@ public class SaveManager {
.forEach(field -> {
final AbstractSave save = field.get();
try {
saveObject.add(save.getName(), save.save());
final JsonElement saveData = save.save();
if (saveData != null) {
saveObject.add(save.getName(), saveData);
}
} catch (Throwable e) {
Logger.LOGGER.error("Failed to save save " + save.getName(), e);
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.viaproxy.util.logging.Logger;
public class SaveMigrator {
public static void migrate(final SaveManager saveManager, final JsonObject jsonObject) {
try {
if (jsonObject.has("accounts")) {
for (JsonElement element : jsonObject.getAsJsonArray("accounts")) {
final JsonObject object = element.getAsJsonObject();
if (object.has("is_offline_mode_account") && object.get("is_offline_mode_account").getAsBoolean()) {
saveManager.accountsSave.addAccount(object.get("name").getAsString());
} else {
saveManager.accountsSave.addAccount(MinecraftAuth.Java.Title.MC_PROFILE.fromJson(object));
}
}
}
} catch (Throwable e) {
Logger.LOGGER.error("Failed to migrate accounts save", e);
}
}
}

View File

@ -1,112 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.java.StepGameOwnership;
import net.raphimc.mcauth.step.java.StepMCProfile;
import net.raphimc.mcauth.util.MicrosoftConstants;
import net.raphimc.viaproxy.saves.AbstractSave;
import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class AccountsSave extends AbstractSave {
private List<StepMCProfile.MCProfile> accounts = new ArrayList<>();
public AccountsSave() {
super("accounts");
}
@Override
public void load(JsonElement jsonElement) throws Exception {
this.accounts = new ArrayList<>();
for (JsonElement element : jsonElement.getAsJsonArray()) {
final JsonObject object = element.getAsJsonObject();
if (object.has("is_offline_mode_account") && object.get("is_offline_mode_account").getAsBoolean()) {
this.addOfflineAccount(object.get("name").getAsString());
} else {
this.addAccount(MinecraftAuth.Java.Title.MC_PROFILE.fromJson(object));
}
}
}
@Override
public JsonElement save() {
final JsonArray array = new JsonArray();
for (StepMCProfile.MCProfile account : this.accounts) {
if (account.prevResult().items().isEmpty()) {
final JsonObject object = new JsonObject();
object.addProperty("is_offline_mode_account", true);
object.addProperty("name", account.name());
array.add(object);
} else {
array.add(account.toJson());
}
}
return array;
}
public StepMCProfile.MCProfile addAccount(final StepMCProfile.MCProfile profile) {
this.accounts.add(profile);
return profile;
}
public StepMCProfile.MCProfile addAccount(final int index, final StepMCProfile.MCProfile profile) {
this.accounts.add(index, profile);
return profile;
}
public StepMCProfile.MCProfile addOfflineAccount(final String name) {
return this.addAccount(new StepMCProfile.MCProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes()), name, null, new StepGameOwnership.GameOwnership(Collections.emptyList(), null)));
}
public void removeAccount(final StepMCProfile.MCProfile profile) {
this.accounts.remove(profile);
}
public void refreshAccounts() {
final List<StepMCProfile.MCProfile> accounts = new ArrayList<>();
for (StepMCProfile.MCProfile account : this.accounts) {
if (account.prevResult().items().isEmpty()) {
accounts.add(account);
continue;
}
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
accounts.add(MinecraftAuth.Java.Title.MC_PROFILE.refresh(httpClient, account));
} catch (Throwable e) {
Logger.LOGGER.error("Failed to refresh account " + account.name() + ", removing it from the list.", e);
}
}
this.accounts = accounts;
}
public List<StepMCProfile.MCProfile> getAccounts() {
return Collections.unmodifiableList(this.accounts);
}
}

View File

@ -0,0 +1,115 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import net.raphimc.mcauth.step.java.StepMCProfile;
import net.raphimc.mcauth.util.MicrosoftConstants;
import net.raphimc.viaproxy.saves.AbstractSave;
import net.raphimc.viaproxy.saves.impl.accounts.Account;
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class NewAccountsSave extends AbstractSave {
private List<Account> accounts = new ArrayList<>();
public NewAccountsSave() {
super("new_accounts");
}
@Override
public void load(JsonElement jsonElement) throws Exception {
this.accounts = new ArrayList<>();
for (JsonElement element : jsonElement.getAsJsonArray()) {
final JsonObject jsonObject = element.getAsJsonObject();
final String type = jsonObject.get("account_type").getAsString();
final Class<?> clazz = Class.forName(type);
final Account account = (Account) clazz.getConstructor(JsonObject.class).newInstance(jsonObject);
this.accounts.add(account);
}
}
@Override
public JsonElement save() throws Throwable {
final JsonArray array = new JsonArray();
for (Account account : this.accounts) {
final JsonObject jsonObject = account.toJson();
jsonObject.addProperty("account_type", account.getClass().getName());
array.add(jsonObject);
}
return array;
}
public Account addAccount(final StepMCProfile.MCProfile mcProfile) {
if (mcProfile.prevResult().items().isEmpty()) {
return this.addAccount(mcProfile.name());
} else {
final Account account = new MicrosoftAccount(mcProfile);
this.accounts.add(account);
return account;
}
}
public Account addAccount(final StepMCChain.MCChain mcChain) {
final Account account = new BedrockAccount(mcChain);
this.accounts.add(account);
return account;
}
public Account addAccount(final String username) {
final Account account = new OfflineAccount(username);
this.accounts.add(account);
return account;
}
public Account addAccount(final int index, final Account account) {
this.accounts.add(index, account);
return account;
}
public void removeAccount(final Account account) {
this.accounts.remove(account);
}
public void refreshAccounts() {
for (Account account : new ArrayList<>(this.accounts)) {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
account.refresh(httpClient);
} catch (Throwable e) {
this.accounts.remove(account);
Logger.LOGGER.error("Failed to refresh account " + account.getName() + ", removing it from the list.", e);
}
}
}
public List<Account> getAccounts() {
return Collections.unmodifiableList(this.accounts);
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID;
public abstract class Account {
public Account() {
}
public abstract JsonObject toJson() throws Throwable;
public abstract String getName();
public abstract UUID getUUID();
public GameProfile getGameProfile() {
return new GameProfile(this.getUUID(), this.getName());
}
public abstract String getDisplayString();
public abstract void refresh(final CloseableHttpClient httpClient) throws Throwable;
}

View File

@ -0,0 +1,68 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID;
public class BedrockAccount extends Account {
private StepMCChain.MCChain mcChain;
public BedrockAccount(final JsonObject jsonObject) throws Throwable {
this.mcChain = MinecraftAuth.Bedrock.Title.MC_CHAIN.fromJson(jsonObject);
}
public BedrockAccount(final StepMCChain.MCChain mcChain) {
this.mcChain = mcChain;
}
@Override
public JsonObject toJson() {
return this.mcChain.toJson();
}
@Override
public String getName() {
return this.mcChain.displayName();
}
@Override
public UUID getUUID() {
return this.mcChain.id();
}
public StepMCChain.MCChain getMcChain() {
return this.mcChain;
}
@Override
public String getDisplayString() {
return this.getName() + " (Bedrock)";
}
@Override
public void refresh(CloseableHttpClient httpClient) throws Exception {
this.mcChain = MinecraftAuth.Bedrock.Title.MC_CHAIN.refresh(httpClient, this.mcChain);
}
}

View File

@ -0,0 +1,68 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.java.StepMCProfile;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID;
public class MicrosoftAccount extends Account {
private StepMCProfile.MCProfile mcProfile;
public MicrosoftAccount(final JsonObject jsonObject) throws Throwable {
this.mcProfile = MinecraftAuth.Java.Title.MC_PROFILE.fromJson(jsonObject);
}
public MicrosoftAccount(final StepMCProfile.MCProfile mcProfile) {
this.mcProfile = mcProfile;
}
@Override
public JsonObject toJson() {
return this.mcProfile.toJson();
}
@Override
public String getName() {
return this.mcProfile.name();
}
@Override
public UUID getUUID() {
return this.mcProfile.id();
}
public StepMCProfile.MCProfile getMcProfile() {
return this.mcProfile;
}
@Override
public String getDisplayString() {
return this.getName() + " (Microsoft)";
}
@Override
public void refresh(CloseableHttpClient httpClient) throws Exception {
this.mcProfile = MinecraftAuth.Java.Title.MC_PROFILE.refresh(httpClient, this.mcProfile);
}
}

View File

@ -0,0 +1,67 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID;
public class OfflineAccount extends Account {
private final String name;
private final UUID uuid;
public OfflineAccount(JsonObject jsonObject) {
this.name = jsonObject.get("name").getAsString();
this.uuid = UUID.fromString(jsonObject.get("uuid").getAsString());
}
public OfflineAccount(final String name) {
this.name = name;
this.uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes());
}
@Override
public JsonObject toJson() {
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("name", this.name);
jsonObject.addProperty("uuid", this.uuid.toString());
return jsonObject;
}
@Override
public String getName() {
return this.name;
}
@Override
public UUID getUUID() {
return this.uuid;
}
@Override
public String getDisplayString() {
return this.name + " (Offline)";
}
@Override
public void refresh(CloseableHttpClient httpClient) {
}
}

View File

@ -21,6 +21,7 @@ import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.java.StepMCProfile;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.saves.impl.accounts.Account;
import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
@ -126,7 +127,7 @@ public class AccountsTab extends AUITab {
else this.markSelected(0);
}
final StepMCProfile.MCProfile account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
final Account account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
if (account != null) {
ViaProxy.saveManager.accountsSave.removeAccount(account);
ViaProxy.saveManager.save();
@ -163,7 +164,7 @@ public class AccountsTab extends AUITab {
addOfflineAccountButton.addActionListener(event -> {
String username = JOptionPane.showInputDialog(this.frame, "Enter your offline mode Username:", "Add Offline Account", JOptionPane.PLAIN_MESSAGE);
if (username != null && !username.trim().isEmpty()) {
StepMCProfile.MCProfile account = ViaProxy.saveManager.accountsSave.addOfflineAccount(username);
Account account = ViaProxy.saveManager.accountsSave.addAccount(username);
ViaProxy.saveManager.save();
this.addAccount(account);
}
@ -187,9 +188,9 @@ public class AccountsTab extends AUITab {
});
SwingUtilities.invokeLater(() -> {
this.closePopup();
ViaProxy.saveManager.accountsSave.addAccount(profile);
Account account = ViaProxy.saveManager.accountsSave.addAccount(profile);
ViaProxy.saveManager.save();
this.addAccount(profile);
this.addAccount(account);
this.frame.showInfo("The account " + profile.name() + " was added successfully.");
});
} catch (InterruptedException ignored) {
@ -227,10 +228,9 @@ public class AccountsTab extends AUITab {
this.addMicrosoftAccountButton.setEnabled(true);
}
private void addAccount(final StepMCProfile.MCProfile account) {
private void addAccount(final Account account) {
DefaultListModel<String> model = (DefaultListModel<String>) this.accountsList.getModel();
if (account.prevResult().items().isEmpty()) model.addElement(account.name() + " (Offline)");
else model.addElement(account.name() + " (Microsoft)");
model.addElement(account.getDisplayString());
}
public void markSelected(final int index) {
@ -243,7 +243,7 @@ public class AccountsTab extends AUITab {
for (int i = 0; i < model.getSize(); i++) model.setElementAt(model.getElementAt(i).replaceAll("<[^>]+>", ""), i);
model.setElementAt("<html><span style=\"color:rgb(0, 180, 0)\"><b>" + model.getElementAt(index) + "</b></span></html>", index);
StepMCProfile.MCProfile account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
Account account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
if (account != null) Options.MC_ACCOUNT = account;
else throw new IllegalStateException("Account is null"); //Lists desynced
}
@ -255,7 +255,7 @@ public class AccountsTab extends AUITab {
model.add(index - 1, name);
this.accountsList.setSelectedIndex(index - 1);
StepMCProfile.MCProfile account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
Account account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
if (account != null) {
ViaProxy.saveManager.accountsSave.removeAccount(account);
ViaProxy.saveManager.accountsSave.addAccount(index - 1, account);
@ -272,7 +272,7 @@ public class AccountsTab extends AUITab {
model.add(index + 1, name);
this.accountsList.setSelectedIndex(index + 1);
StepMCProfile.MCProfile account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
Account account = ViaProxy.saveManager.accountsSave.getAccounts().get(index);
if (account != null) {
ViaProxy.saveManager.accountsSave.removeAccount(account);
ViaProxy.saveManager.accountsSave.addAccount(index + 1, account);