From dab3a6f59af8a811c2d8c09b81ddefac6a03575a Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Thu, 10 Oct 2024 20:21:17 +0200 Subject: [PATCH] Fix player target variables & make score optional (#1410) Signed-off-by: Pablo Herrera --- .../pgm/variables/types/PlayerLocationVariable.java | 2 +- .../tc/oc/pgm/variables/types/ScoreVariable.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/variables/types/PlayerLocationVariable.java b/core/src/main/java/tc/oc/pgm/variables/types/PlayerLocationVariable.java index 4804b93590..565e46577b 100644 --- a/core/src/main/java/tc/oc/pgm/variables/types/PlayerLocationVariable.java +++ b/core/src/main/java/tc/oc/pgm/variables/types/PlayerLocationVariable.java @@ -81,7 +81,7 @@ public enum Component { private static RayBlockIntersection intersection(MatchPlayer player) { RayCastCache cache = lastRaytrace; - if (player.getLocation().equals(cache.location)) { + if (cache != null && player.getLocation().equals(cache.location)) { return cache.rayCast; } lastRaytrace = cache = new RayCastCache( diff --git a/core/src/main/java/tc/oc/pgm/variables/types/ScoreVariable.java b/core/src/main/java/tc/oc/pgm/variables/types/ScoreVariable.java index 666b09ed21..69f0ad5123 100644 --- a/core/src/main/java/tc/oc/pgm/variables/types/ScoreVariable.java +++ b/core/src/main/java/tc/oc/pgm/variables/types/ScoreVariable.java @@ -13,14 +13,17 @@ public ScoreVariable() { @Override protected double getValueImpl(Party party) { - if (party instanceof Competitor) - return party.moduleRequire(ScoreMatchModule.class).getScore((Competitor) party); - return 0; + if (party instanceof Competitor c) + return party + .moduleOptional(ScoreMatchModule.class) + .map(smm -> smm.getScore(c)) + .orElse(-1d); + return -1; } @Override protected void setValueImpl(Party party, double value) { - if (party instanceof Competitor) - party.moduleRequire(ScoreMatchModule.class).setScore((Competitor) party, value); + if (party instanceof Competitor c) + party.moduleOptional(ScoreMatchModule.class).ifPresent(smm -> smm.setScore(c, value)); } }