1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Some null checks in playerManager

This commit is contained in:
montlikadani 2019-08-14 14:13:15 +02:00
parent 355074dffd
commit d1417cc35a

View File

@ -104,24 +104,28 @@ public class PlayerManager {
} }
public void addPlayerToCache(JobsPlayer jPlayer) { public void addPlayerToCache(JobsPlayer jPlayer) {
if (jPlayer.getUserName() != null) if (jPlayer.getUserName() != null && playersCache.get(jPlayer.getUserName().toLowerCase()) == null)
playersCache.put(jPlayer.getUserName().toLowerCase(), jPlayer); playersCache.put(jPlayer.getUserName().toLowerCase(), jPlayer);
if (jPlayer.getPlayerUUID() != null) if (jPlayer.getPlayerUUID() != null && playersUUIDCache.get(jPlayer.getPlayerUUID()) == null)
playersUUIDCache.put(jPlayer.getPlayerUUID(), jPlayer); playersUUIDCache.put(jPlayer.getPlayerUUID(), jPlayer);
} }
public void addPlayer(JobsPlayer jPlayer) { public void addPlayer(JobsPlayer jPlayer) {
if (jPlayer.getUserName() != null) if (jPlayer.getUserName() != null && players.get(jPlayer.getUserName().toLowerCase()) == null)
players.put(jPlayer.getUserName().toLowerCase(), jPlayer); players.put(jPlayer.getUserName().toLowerCase(), jPlayer);
if (jPlayer.getPlayerUUID() != null) if (jPlayer.getPlayerUUID() != null && playersUUID.get(jPlayer.getPlayerUUID()) == null)
playersUUID.put(jPlayer.getPlayerUUID(), jPlayer); playersUUID.put(jPlayer.getPlayerUUID(), jPlayer);
} }
public JobsPlayer removePlayer(Player player) { public JobsPlayer removePlayer(Player player) {
if (player == null) if (player == null)
return null; return null;
players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = playersUUID.remove(player.getUniqueId()); if (players.get(player.getName()) != null)
players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = playersUUID.get(player.getUniqueId()) != null ?
playersUUID.remove(player.getUniqueId()) : null;
return jPlayer; return jPlayer;
} }
@ -197,6 +201,7 @@ public class PlayerManager {
JobsPlayer jPlayer = getJobsPlayer(player); JobsPlayer jPlayer = getJobsPlayer(player);
if (jPlayer == null) if (jPlayer == null)
return; return;
if (Jobs.getGCManager().saveOnDisconnect()) { if (Jobs.getGCManager().saveOnDisconnect()) {
jPlayer.onDisconnect(); jPlayer.onDisconnect();
jPlayer.save(); jPlayer.save();