save reading in case of wrong data fix #74
This commit is contained in:
parent
70f7b4e69a
commit
44faf46073
@ -14,6 +14,7 @@ import java.io.File;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.DateTimeException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -40,9 +41,15 @@ public class OfflinePlayerData implements IPlayerData {
|
|||||||
FileReader reader = new FileReader(file);
|
FileReader reader = new FileReader(file);
|
||||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||||
reader.close();
|
reader.close();
|
||||||
claim = obj.get("ClaimBlocks").getAsInt();
|
claim = ConfigHandler.fromJson(obj, "ClaimBlocks", claim);
|
||||||
add = obj.get("AdditionalBlocks").getAsInt();
|
add = ConfigHandler.fromJson(obj, "AdditionalBlocks", add);
|
||||||
last = LocalDateTime.parse(obj.get("LastSeen").getAsString(), Flan.onlineTimeFormatter);
|
if(obj.has("LastSeen")) {
|
||||||
|
try {
|
||||||
|
last = LocalDateTime.parse(obj.get("LastSeen").getAsString(), Flan.onlineTimeFormatter);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Flan.log("Error parsing time for {}, ignoring", uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -63,10 +70,14 @@ public class OfflinePlayerData implements IPlayerData {
|
|||||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
claim = obj.get("ClaimBlocks").getAsInt();
|
claim = ConfigHandler.fromJson(obj, "ClaimBlocks", claim);
|
||||||
add = obj.get("AdditionalBlocks").getAsInt();
|
add = ConfigHandler.fromJson(obj, "AdditionalBlocks", add);
|
||||||
if (obj.has("LastSeen")) {
|
if (obj.has("LastSeen")) {
|
||||||
last = LocalDateTime.parse(obj.get("LastSeen").getAsString(), Flan.onlineTimeFormatter);
|
try {
|
||||||
|
last = LocalDateTime.parse(obj.get("LastSeen").getAsString(), Flan.onlineTimeFormatter);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Flan.log("Error parsing time for {}, ignoring", uuid);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
obj.addProperty("LastSeen", last.format(Flan.onlineTimeFormatter));
|
obj.addProperty("LastSeen", last.format(Flan.onlineTimeFormatter));
|
||||||
FileWriter write = new FileWriter(dataFile);
|
FileWriter write = new FileWriter(dataFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user