refactor of watchers to use map functions

This commit is contained in:
ingmargoudt 2017-02-15 23:19:40 +01:00
parent fbbfc6c611
commit 4aa51210f9
18 changed files with 69 additions and 158 deletions

View file

@ -65,23 +65,14 @@ public class PlayerGainedLifeWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.GAINED_LIFE) {
UUID playerId = event.getPlayerId();
if (playerId != null) {
Integer amount = amountOfLifeGainedThisTurn.get(playerId);
if (amount == null) {
amount = event.getAmount();
} else {
amount = amount + event.getAmount();
}
amountOfLifeGainedThisTurn.put(playerId, amount);
amountOfLifeGainedThisTurn.putIfAbsent(playerId, 0);
amountOfLifeGainedThisTurn.compute(playerId, (p, amount) -> amount +event.getAmount());
}
}
}
public int getLiveGained(UUID playerId) {
Integer amount = amountOfLifeGainedThisTurn.get(playerId);
if (amount != null) {
return amount;
}
return 0;
return amountOfLifeGainedThisTurn.getOrDefault(playerId, 0);
}
@Override