修复添加账号时未选中验证服务器会NPE
This commit is contained in:
@@ -125,34 +125,51 @@ public class AddAccountPane extends StackPane {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onCreationAccept() {
|
private void onCreationAccept() {
|
||||||
int type = cboType.getSelectionModel().getSelectedIndex();
|
|
||||||
String username = txtUsername.getText();
|
String username = txtUsername.getText();
|
||||||
String password = txtPassword.getText();
|
String password = txtPassword.getText();
|
||||||
String apiRoot = Optional.ofNullable(cboServers.getSelectionModel().getSelectedItem()).map(AuthlibInjectorServer::getUrl).orElse(null);
|
Object addtionalData;
|
||||||
|
|
||||||
|
int type = cboType.getSelectionModel().getSelectedIndex();
|
||||||
|
AccountFactory<?> factory;
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
factory = Accounts.ACCOUNT_FACTORY.get(Accounts.OFFLINE_ACCOUNT_KEY);
|
||||||
|
addtionalData = null;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
factory = Accounts.ACCOUNT_FACTORY.get(Accounts.YGGDRASIL_ACCOUNT_KEY);
|
||||||
|
addtionalData = null;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
factory = Accounts.ACCOUNT_FACTORY.get(Accounts.AUTHLIB_INJECTOR_ACCOUNT_KEY);
|
||||||
|
Optional<AuthlibInjectorServer> server = Optional.ofNullable(cboServers.getSelectionModel().getSelectedItem());
|
||||||
|
if (server.isPresent()) {
|
||||||
|
addtionalData = server.get().getUrl();
|
||||||
|
} else {
|
||||||
|
lblCreationWarning.setText(Launcher.i18n("account.failed.no_selected_server"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
showSpinner();
|
showSpinner();
|
||||||
lblCreationWarning.setText("");
|
lblCreationWarning.setText("");
|
||||||
Task.ofResult("create_account", () -> {
|
|
||||||
AccountFactory<?> factory;
|
|
||||||
switch (type) {
|
|
||||||
case 0: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.OFFLINE_ACCOUNT_KEY); break;
|
|
||||||
case 1: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.YGGDRASIL_ACCOUNT_KEY); break;
|
|
||||||
case 2: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.AUTHLIB_INJECTOR_ACCOUNT_KEY); break;
|
|
||||||
default: throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
return factory.create(new Selector(), username, password, apiRoot, Settings.INSTANCE.getProxy());
|
Task.ofResult("create_account", () -> factory.create(new Selector(), username, password, addtionalData, Settings.INSTANCE.getProxy()))
|
||||||
}).finalized(Schedulers.javafx(), variables -> {
|
.finalized(Schedulers.javafx(), variables -> {
|
||||||
Settings.INSTANCE.addAccount(variables.get("create_account"));
|
Settings.INSTANCE.addAccount(variables.get("create_account"));
|
||||||
hideSpinner();
|
hideSpinner();
|
||||||
finalization.accept(this);
|
finalization.accept(this);
|
||||||
}, exception -> {
|
}, exception -> {
|
||||||
if (exception instanceof NoSelectedCharacterException) {
|
if (exception instanceof NoSelectedCharacterException) {
|
||||||
finalization.accept(this);
|
finalization.accept(this);
|
||||||
} else {
|
} else {
|
||||||
lblCreationWarning.setText(accountException(exception));
|
lblCreationWarning.setText(accountException(exception));
|
||||||
}
|
}
|
||||||
hideSpinner();
|
hideSpinner();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ account.failed.invalid_credentials=Incorrect password. Or forbidden to log in te
|
|||||||
account.failed.invalid_password=Invalid password
|
account.failed.invalid_password=Invalid password
|
||||||
account.failed.invalid_token=Please log out and re-input your password to log in.
|
account.failed.invalid_token=Please log out and re-input your password to log in.
|
||||||
account.failed.no_charactor=No character in this account.
|
account.failed.no_charactor=No character in this account.
|
||||||
|
account.failed.no_selected_server=No authentication server is selected.
|
||||||
account.injector.add=Add authentication server
|
account.injector.add=Add authentication server
|
||||||
account.injector.manage=Manage authentication servers
|
account.injector.manage=Manage authentication servers
|
||||||
account.injector.http=Warning: This server is using HTTP, which will cause your password be transmitted in clear text.
|
account.injector.http=Warning: This server is using HTTP, which will cause your password be transmitted in clear text.
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ account.failed.invalid_credentials=您的用户名或密码错误,或者登录
|
|||||||
account.failed.invalid_password=无效的密码
|
account.failed.invalid_password=无效的密码
|
||||||
account.failed.invalid_token=请尝试登出并重新输入密码登录
|
account.failed.invalid_token=请尝试登出并重新输入密码登录
|
||||||
account.failed.no_charactor=该帐号没有角色
|
account.failed.no_charactor=该帐号没有角色
|
||||||
|
account.failed.no_selected_server=未选择认证服务器
|
||||||
account.injector.add=添加认证服务器
|
account.injector.add=添加认证服务器
|
||||||
account.injector.manage=管理认证服务器
|
account.injector.manage=管理认证服务器
|
||||||
account.injector.http=警告:此服务器使用不安全的http协议,您的密码在登录时会被明文传输。
|
account.injector.http=警告:此服务器使用不安全的http协议,您的密码在登录时会被明文传输。
|
||||||
|
|||||||
Reference in New Issue
Block a user