mirror of
https://github.com/CarmJos/MoeTeleport.git
synced 2024-09-19 21:35:56 +00:00
修复报错空lastLocation的问题
This commit is contained in:
parent
623fc36c20
commit
e186e5ea0a
@ -16,7 +16,6 @@ import java.io.File;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class JSONStorage extends FileBasedStorage {
|
public class JSONStorage extends FileBasedStorage {
|
||||||
@ -36,13 +35,13 @@ public class JSONStorage extends FileBasedStorage {
|
|||||||
if (!dataElement.isJsonObject()) throw new NullPointerException(userDataFile.getName());
|
if (!dataElement.isJsonObject()) throw new NullPointerException(userDataFile.getName());
|
||||||
|
|
||||||
JsonObject dataObject = dataElement.getAsJsonObject();
|
JsonObject dataObject = dataElement.getAsJsonObject();
|
||||||
|
DataLocation lastLocation = null;
|
||||||
DataLocation lastLocation = Optional
|
if (dataObject.has("lastLocation")) {
|
||||||
.ofNullable(dataObject.get("lastLocation").getAsString())
|
lastLocation = DataLocation.deserializeText(dataObject.get("lastLocation").getAsString());
|
||||||
.map(DataLocation::deserializeText)
|
}
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
LinkedHashMap<String, DataLocation> homeData = new LinkedHashMap<>();
|
LinkedHashMap<String, DataLocation> homeData = new LinkedHashMap<>();
|
||||||
|
if (dataObject.has("homes")) {
|
||||||
JsonObject homesObject = dataObject.getAsJsonObject("homes");
|
JsonObject homesObject = dataObject.getAsJsonObject("homes");
|
||||||
if (homesObject != null) {
|
if (homesObject != null) {
|
||||||
homesObject.entrySet().forEach(entry -> {
|
homesObject.entrySet().forEach(entry -> {
|
||||||
@ -50,6 +49,7 @@ public class JSONStorage extends FileBasedStorage {
|
|||||||
if (location != null) homeData.put(entry.getKey(), location);
|
if (location != null) homeData.put(entry.getKey(), location);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new UserData(uuid, lastLocation, homeData);
|
return new UserData(uuid, lastLocation, homeData);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user