Fix NPE for new data tracker

This commit is contained in:
nossr50 2019-06-05 21:43:07 -07:00
parent 3ce3ac5350
commit 426b2d27e7

View File

@ -16,9 +16,7 @@ public final class UserManager {
private static HashSet<McMMOPlayer> playerDataSet; //Used to track players for sync saves on shutdown
private UserManager() {
playerDataSet = new HashSet<>();
}
private UserManager() {}
/**
* Track a new user.
@ -27,6 +25,10 @@ public final class UserManager {
*/
public static void track(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.getPlayer().setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
if(playerDataSet == null)
playerDataSet = new HashSet<>();
playerDataSet.add(mcMMOPlayer); //for sync saves on shutdown
}
@ -42,6 +44,8 @@ public final class UserManager {
public static void remove(Player player) {
McMMOPlayer mcMMOPlayer = getPlayer(player);
player.removeMetadata(mcMMO.playerDataKey, mcMMO.p);
if(playerDataSet != null && playerDataSet.contains(mcMMOPlayer))
playerDataSet.remove(mcMMOPlayer); //Clear sync save tracking
}
@ -53,6 +57,7 @@ public final class UserManager {
remove(player);
}
if(playerDataSet != null)
playerDataSet.clear(); //Clear sync save tracking
}