From 716a95ec28b448c75557cb821e27ed4fcbfab458 Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Mon, 28 Oct 2024 19:49:20 +0100 Subject: [PATCH] Avoid exceptions using lives on non-blitz matches (#1414) 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)); } }