forked from External/mage
refactor of watchers to use map functions
This commit is contained in:
parent
fbbfc6c611
commit
4aa51210f9
18 changed files with 69 additions and 158 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue