Skip to content

Commit

Permalink
Avoid exceptions using lives on non-blitz matches (#1414)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Oct 28, 2024
1 parent 80e5c27 commit 716a95e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ public LivesVariable() {

@Override
protected double getValueImpl(MatchPlayer player) {
return player.moduleRequire(BlitzMatchModule.class).getNumOfLives(player.getId());
return player
.moduleOptional(BlitzMatchModule.class)
.map(bmm -> bmm.getNumOfLives(player.getId()))
.orElse(-1);
}

@Override
protected void setValueImpl(MatchPlayer player, double value) {
player.moduleRequire(BlitzMatchModule.class).setLives(player, Math.max((int) value, 0));
int amt = Math.max((int) value, 0);
player.moduleOptional(BlitzMatchModule.class).ifPresent(bmm -> bmm.setLives(player, amt));
}
}

0 comments on commit 716a95e

Please sign in to comment.