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,6 +73,7 @@ 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;
try {
Map<String, JSONFPlayer> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFPlayer>>() { Map<String, JSONFPlayer> data = this.gson.fromJson(content, new TypeToken<Map<String, JSONFPlayer>>() {
}.getType()); }.getType());
Set<String> list = new HashSet<>(); Set<String> list = new HashSet<>();
@ -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) {