Make DPlayers getters a bit more robust. Should resolve #181

This commit is contained in:
Daniel Saukel 2016-12-17 01:52:22 +01:00
parent 4133e20471
commit 921a609830

View File

@ -41,7 +41,7 @@ public class DPlayers {
}
}
return null;
return new DGlobalPlayer(player);
}
/**
@ -95,11 +95,7 @@ public class DPlayers {
* an instance of DGlobalPlayer to add
*/
public void addPlayer(DGlobalPlayer player) {
for (DGlobalPlayer dGlobalPlayer : dGlobalPlayers) {
if (dGlobalPlayer.getPlayer().equals(player.getPlayer())) {
dGlobalPlayers.remove(dGlobalPlayer);
}
}
removePlayer(player);
dGlobalPlayers.add(player);
}
@ -109,7 +105,16 @@ public class DPlayers {
* an instance of DGlobalPlayer to remove
*/
public void removePlayer(DGlobalPlayer player) {
dGlobalPlayers.remove(player);
if (dGlobalPlayers.remove(player)) {
return;
}
// Fallback check just in case an old Player instance is kept
for (DGlobalPlayer dGlobalPlayer : dGlobalPlayers) {
if (dGlobalPlayer.getName().equals(player.getName())) {
dGlobalPlayers.remove(dGlobalPlayer);
}
}
}
/**