Skip to content

Commit

Permalink
Fix player target variables & make score optional (#1410)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <pabloherrerapalacio@gmail.com>
  • Loading branch information
Pablete1234 committed Nov 30, 2024
1 parent 511161f commit dab3a6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 8 additions & 5 deletions core/src/main/java/tc/oc/pgm/variables/types/ScoreVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit dab3a6f

Please sign in to comment.