From c06af490eb7fc058daafb8d833f2df1e1aad62a6 Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Mon, 28 Oct 2024 12:34:31 +0100 Subject: [PATCH] Avoid exceptions using lives on non-blitz matches Signed-off-by: Pablo Herrera --- .../java/tc/oc/pgm/variables/types/LivesVariable.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/variables/types/LivesVariable.java b/core/src/main/java/tc/oc/pgm/variables/types/LivesVariable.java index 462feb5a57..5d5a11a8d5 100644 --- a/core/src/main/java/tc/oc/pgm/variables/types/LivesVariable.java +++ b/core/src/main/java/tc/oc/pgm/variables/types/LivesVariable.java @@ -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)); } }