mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-14 20:21:34 +01:00
improved ClassiCube Account handling
This commit is contained in:
parent
e56f06097c
commit
1381141e13
@ -37,6 +37,9 @@ public class ClassiCubeAccountHandler extends FileSaver {
|
||||
|
||||
private CCAccount account;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public ClassiCubeAccountHandler() {
|
||||
super("classicube.account");
|
||||
|
||||
@ -45,28 +48,33 @@ public class ClassiCubeAccountHandler extends FileSaver {
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {
|
||||
if (account == null) return;
|
||||
|
||||
account.token = null; // Token has to be created next time
|
||||
for (Map.Entry<String, JsonElement> entry : account.asJson().entrySet()) {
|
||||
object.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
object.addProperty("username", username);
|
||||
object.addProperty("password", password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(JsonObject object) {
|
||||
try {
|
||||
account = CCAccount.fromJson(object);
|
||||
} catch (Exception e) {
|
||||
ViaFabricPlus.LOGGER.warn("No ClassiCube account could be found");
|
||||
}
|
||||
if (object.has("username")) username = object.get("username").getAsString();
|
||||
if (object.has("password")) password = object.get("password").getAsString();
|
||||
}
|
||||
|
||||
public CCAccount getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setAccount(CCAccount account) {
|
||||
this.account = account;
|
||||
if (account != null) {
|
||||
username = account.username();
|
||||
password = account.password();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package de.florianmichael.viafabricplus.ui.screen.impl.base;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.classic4j.BetaCraftHandler;
|
||||
import de.florianmichael.classic4j.model.classicube.highlevel.CCAccount;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.ClassiCubeAccountHandler;
|
||||
import de.florianmichael.viafabricplus.ui.screen.VFPScreen;
|
||||
import de.florianmichael.viafabricplus.ui.screen.impl.thirdparty.classicube.ClassiCubeLoginScreen;
|
||||
@ -55,15 +54,16 @@ public class ProtocolSelectionScreen extends VFPScreen {
|
||||
|
||||
// ClassiCube
|
||||
|
||||
final CCAccount classiCubeAccount = ClassiCubeAccountHandler.INSTANCE.getAccount();
|
||||
final boolean loggedIn = ClassiCubeAccountHandler.INSTANCE.getAccount() != null;
|
||||
|
||||
ButtonWidget.Builder classiCubeBuilder = ButtonWidget.builder(Text.literal("ClassiCube"), button -> {
|
||||
if (classiCubeAccount == null || classiCubeAccount.token == null) {
|
||||
if (!loggedIn) {
|
||||
ClassiCubeLoginScreen.INSTANCE.open(prevScreen);
|
||||
return;
|
||||
}
|
||||
ClassiCubeServerListScreen.INSTANCE.open(prevScreen);
|
||||
}).position(width - 98 - 5, height - 25).size(98, 20);
|
||||
if (classiCubeAccount == null || classiCubeAccount.token == null) {
|
||||
if (!loggedIn) {
|
||||
classiCubeBuilder = classiCubeBuilder.tooltip(Tooltip.of(Text.translatable("classicube.viafabricplus.warning")));
|
||||
}
|
||||
this.addDrawableChild(classiCubeBuilder.build());
|
||||
|
@ -32,7 +32,6 @@ import net.minecraft.text.Text;
|
||||
|
||||
public class ClassiCubeLoginScreen extends VFPScreen {
|
||||
public final static ClassiCubeLoginScreen INSTANCE = new ClassiCubeLoginScreen();
|
||||
public Screen prevScreen;
|
||||
|
||||
public ClassiCubeLoginScreen() {
|
||||
super("ClassiCube Login", false);
|
||||
@ -64,11 +63,8 @@ public class ClassiCubeLoginScreen extends VFPScreen {
|
||||
nameField.setMaxLength(Integer.MAX_VALUE);
|
||||
passwordField.setMaxLength(Integer.MAX_VALUE);
|
||||
|
||||
final CCAccount classiCubeAccount = ClassiCubeAccountHandler.INSTANCE.getAccount();
|
||||
if (classiCubeAccount != null) {
|
||||
nameField.setText(classiCubeAccount.username());
|
||||
passwordField.setText(classiCubeAccount.password());
|
||||
}
|
||||
nameField.setText(ClassiCubeAccountHandler.INSTANCE.getUsername());
|
||||
passwordField.setText(ClassiCubeAccountHandler.INSTANCE.getPassword());
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.literal("Login"), button -> {
|
||||
ClassiCubeAccountHandler.INSTANCE.setAccount(new CCAccount(nameField.getText(), passwordField.getText()));
|
||||
@ -104,6 +100,7 @@ public class ClassiCubeLoginScreen extends VFPScreen {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
ClassiCubeAccountHandler.INSTANCE.setAccount(null);
|
||||
ProtocolSelectionScreen.INSTANCE.open(prevScreen);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class ClassiCubeMFAScreen extends VFPScreen {
|
||||
public final static ClassiCubeMFAScreen INSTANCE = new ClassiCubeMFAScreen();
|
||||
|
||||
public ClassiCubeMFAScreen() {
|
||||
super("ClassiCube MFA", true);
|
||||
super("ClassiCube MFA", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,6 +89,7 @@ public class ClassiCubeMFAScreen extends VFPScreen {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
ClassiCubeAccountHandler.INSTANCE.setAccount(null);
|
||||
ProtocolSelectionScreen.INSTANCE.open(prevScreen);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user