diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/players/PlayerHandler.java b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/players/PlayerHandler.java index b0c9347a..e9a0876a 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/players/PlayerHandler.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/players/PlayerHandler.java @@ -31,23 +31,20 @@ import com.google.gson.Gson; import io.leangen.geantyref.TypeToken; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; -import java.io.Reader; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class PlayerHandler{ private final AdvancedServerList core; private final PluginLogger logger; private final Path cache; - private List cachedPlayers = new ArrayList<>(); private final Type listType = new TypeToken>(){}.getType(); private final Gson gson = new Gson(); @@ -55,6 +52,7 @@ public class PlayerHandler{ // UUID of MHF_Question private final UUID defaultUUID = UUID.fromString("606e2ff0-ed77-4842-9d6c-e1d3321c7838"); + private List cachedPlayers = new ArrayList<>(); private CachedPlayer defaultPlayer = null; public PlayerHandler(AdvancedServerList core){ @@ -75,7 +73,7 @@ public void load(){ } try{ - Reader reader = Files.newBufferedReader(cache); + BufferedReader reader = Files.newBufferedReader(cache); cachedPlayers = gson.fromJson(reader, listType); @@ -85,6 +83,14 @@ public void load(){ return; } + // In case Gson messes up... I guess. + if(cachedPlayers == null){ + logger.warn("Couldn't load players from playercache.json file. Is the JSON valid?"); + // Create new ArrayList instance to avoid further issues. + cachedPlayers = new ArrayList<>(); + return; + } + logger.info("Loaded %d players into cache!", cachedPlayers.size()); } diff --git a/pom.xml b/pom.xml index ee088ac7..56f0d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ UTF-8 - 3.2.0 + 3.2.1 Create multiple Server lists based on conditions. v3.0.0