移除canPlayOffline()
This commit is contained in:
@@ -97,10 +97,8 @@ public final class LauncherHelper {
|
|||||||
try {
|
try {
|
||||||
variables.set("account", account.logIn());
|
variables.set("account", account.logIn());
|
||||||
} catch (ServerDisconnectException e) {
|
} catch (ServerDisconnectException e) {
|
||||||
if (account.canPlayOffline())
|
variables.set("account",
|
||||||
variables.set("account", account.playOffline());
|
account.playOffline().orElseThrow(() -> e));
|
||||||
else
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
} catch (AuthenticationException e) {
|
} catch (AuthenticationException e) {
|
||||||
variables.set("account", DialogController.logIn(account));
|
variables.set("account", DialogController.logIn(account));
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.auth;
|
|||||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,13 +57,11 @@ public abstract class Account {
|
|||||||
*/
|
*/
|
||||||
public abstract AuthInfo logInWithPassword(String password) throws AuthenticationException;
|
public abstract AuthInfo logInWithPassword(String password) throws AuthenticationException;
|
||||||
|
|
||||||
public abstract boolean canPlayOffline();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play offline.
|
* Play offline.
|
||||||
* @return the specific offline player's info.
|
* @return the specific offline player's info.
|
||||||
*/
|
*/
|
||||||
public abstract AuthInfo playOffline();
|
public abstract Optional<AuthInfo> playOffline();
|
||||||
|
|
||||||
public abstract Map<Object, Object> toStorage();
|
public abstract Map<Object, Object> toStorage();
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jackhuang.hmcl.util.UUIDTypeAdapter;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.Lang.mapOf;
|
import static org.jackhuang.hmcl.util.Lang.mapOf;
|
||||||
@@ -80,13 +81,8 @@ public class OfflineAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayOffline() {
|
public Optional<AuthInfo> playOffline() {
|
||||||
return false;
|
return Optional.empty();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AuthInfo playOffline() {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -103,16 +103,11 @@ public class YggdrasilAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayOffline() {
|
public Optional<AuthInfo> playOffline() {
|
||||||
return isLoggedIn() && session.getSelectedProfile() != null && !canPlayOnline();
|
if (isLoggedIn() && session.getSelectedProfile() != null && !canPlayOnline())
|
||||||
}
|
return Optional.of(session.toAuthInfo());
|
||||||
|
|
||||||
@Override
|
return Optional.empty();
|
||||||
public AuthInfo playOffline() {
|
|
||||||
if (!canPlayOffline())
|
|
||||||
throw new IllegalStateException("Current account " + this + " cannot play offline.");
|
|
||||||
|
|
||||||
return session.toAuthInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user