Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fix the account refresh crash
Browse files Browse the repository at this point in the history
  • Loading branch information
CubeWhy committed Aug 4, 2023
1 parent e2b22f0 commit 4c55b63
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
24 changes: 15 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/main/java/org/cubewhy/lunarcn/account/MicrosoftAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.cubewhy.lunarcn.files.configs.AccountConfigFile;
import org.cubewhy.lunarcn.utils.ClientUtils;
import org.cubewhy.lunarcn.utils.MicrosoftAccountUtils;

import java.io.IOException;
import java.util.Date;

import static org.cubewhy.lunarcn.utils.ClientUtils.logger;

public class MicrosoftAccount implements IAccount {
private String userName;
private String uuid;
Expand Down Expand Up @@ -35,12 +38,16 @@ public MicrosoftAccount(String userName, String uuid, String refreshToken) throw
*/

public void refresh() throws IOException {
MicrosoftAccount account = MicrosoftAccountUtils.getInstance().loginWithToken(this.refreshToken);
this.userName = account.userName;
this.uuid = account.uuid;
this.accessToken = account.accessToken;
this.lastFresh = new Date();
AccountConfigFile.getInstance().addAccount(this);
try {
MicrosoftAccount account = MicrosoftAccountUtils.getInstance().loginWithToken(this.refreshToken);
this.userName = account.userName;
this.uuid = account.uuid;
this.accessToken = account.accessToken;
this.lastFresh = new Date();
AccountConfigFile.getInstance().addAccount(this);
} catch (Exception e) {
logger.catching(e);
}
}

/*
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/cubewhy/lunarcn/value/IntValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ public IntValue(String name, int value, int maxValue, int minValue) {
this.minValue = minValue;
}

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}

@Override
public Integer getValue() {
return value;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/cubewhy/lunarcn/value/ListValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cubewhy.lunarcn.value;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class ListValue extends Value<String[]> {

@Override
public String[] getValue() {
return value;
}

@Override
public void setValue(String[] value) {
this.value = value;
}

@Override
public JsonElement toJson() {
JsonArray arr = new JsonArray();
for (String v : value) {
arr.add(new JsonPrimitive(v));
}
return arr;
}

@Override
public void fromJson(@NotNull JsonElement jsonElement) {
ArrayList<String> values = new ArrayList<>();
for (JsonElement v : jsonElement.getAsJsonArray()) {
values.add(v.getAsString());
}
this.value = values.toArray(new String[0]);
}
}

0 comments on commit 4c55b63

Please sign in to comment.