final ProgressDialog dialog = new ProgressDialog(Language.INSTANCE.localize("account" + "" +
".loggingin"), 0, Language.INSTANCE.localize("account.loggingin"),
"Aborting login for " + usernameField.getText());
dialog.addThread(new Thread() {
public void run() {
AuthenticationResponse resp = Authentication.checkAccount(usernameField.getText(),
new String(passwordField.getPassword()));
dialog.setReturnValue(resp);
dialog.close();
}
});
dialog.start();
AuthenticationResponse response = (AuthenticationResponse) dialog.getReturnValue();
if (response != null && !response.hasError()) {
if (accountsComboBox.getSelectedIndex() == 0) {
account = new Account(username, password, response.getSelectedProfile().getName(),
response.getSelectedProfile().getId(), remember);
App.settings.addAccount(account);
LogManager.info("Added Account " + account);
String[] options = {Language.INSTANCE.localize("common.yes"),
Language.INSTANCE.localize("common.no")};
int ret = JOptionPane.showOptionDialog(App.settings.getParent(),
Language.INSTANCE.localize("account.addedswitch"),
Language.INSTANCE.localize("account.added"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (ret == 0) {
App.settings.switchAccount(account);
}
} else {
account = (Account) accountsComboBox.getSelectedItem();
account.setUsername(username);
account.setMinecraftUsername(response.getSelectedProfile().getName());
account.setUUID(response.getSelectedProfile().getId());
if (remember) {
account.setPassword(password);
}
account.setRemember(remember);
LogManager.info("Edited Account " + account);
String[] options = {Language.INSTANCE.localize("common.ok")};
JOptionPane.showOptionDialog(App.settings.getParent(),
Language.INSTANCE.localize("account.editeddone"),
Language.INSTANCE.localize("account.edited"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
}
App.settings.saveAccounts();
App.settings.reloadAccounts();
accountsComboBox.removeAllItems();
accountsComboBox.addItem(fillerAccount);
for (Account accountt : App.settings.getAccounts()) {
accountsComboBox.addItem(accountt);
}
accountsComboBox.setSelectedItem(account);
} else {
LogManager.error((response == null ? "Unknown Error Logging In" : response.getErrorMessage()));
String[] options = {Language.INSTANCE.localize("common.ok")};
JOptionPane.showOptionDialog(App.settings.getParent(),
"<html><p align=\"center\">" + Language.INSTANCE.localize("account.incorrect") +
"<br/><br/>" + (response == null ? "Unknown Error" : response.getErrorMessage
()) + "</p></html>", Language.INSTANCE.localize("account.notadded"),
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
}
}
}