Fix startup error that may happen when factions is shutdown improperly

This commit is contained in:
DroppingAnvil 2020-06-14 16:02:18 -05:00
parent 0444517eec
commit 81ef43768d

View File

@ -73,21 +73,22 @@ public class JSONFPlayers extends MemoryFPlayers {
if (!this.file.exists()) return new HashMap<>(); if (!this.file.exists()) return new HashMap<>();
String content = DiscUtil.readCatch(this.file); String content = DiscUtil.readCatch(this.file);
if (content == null) return null; if (content == null) return null;
Map<String, JSONFPlayer> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFPlayer>>() { try {
}.getType()); Map<String, JSONFPlayer> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFPlayer>>() {
Set<String> list = new HashSet<>(); }.getType());
Set<String> invalidList = new HashSet<>(); Set<String> list = new HashSet<>();
for (Entry<String, JSONFPlayer> entry : data.entrySet()) { Set<String> invalidList = new HashSet<>();
String key = entry.getKey(); for (Entry<String, JSONFPlayer> entry : data.entrySet()) {
entry.getValue().setId(key); String key = entry.getKey();
if (doesKeyNeedMigration(key)) { entry.getValue().setId(key);
if (!isKeyInvalid(key)) { if (doesKeyNeedMigration(key)) {
list.add(key); if (!isKeyInvalid(key)) {
} else { list.add(key);
invalidList.add(key); } else {
invalidList.add(key);
}
} }
} }
}
if (list.size() > 0) { if (list.size() > 0) {
// We've got some converting to do! // We've got some converting to do!
@ -150,6 +151,14 @@ public class JSONFPlayers extends MemoryFPlayers {
Bukkit.getLogger().log(Level.INFO, "Done converting players.json to UUID."); Bukkit.getLogger().log(Level.INFO, "Done converting players.json to UUID.");
} }
return data; return data;
} catch (NullPointerException exception) {
exception.printStackTrace();
if (this.file.length() < 200) {
return new HashMap<>();
} else {
throw exception;
}
}
} }
private boolean doesKeyNeedMigration(String key) { private boolean doesKeyNeedMigration(String key) {