Skip to content

Commit

Permalink
Return isNegative() and not false, if CondIsWithin is invalid (#7038)
Browse files Browse the repository at this point in the history
* Return isNegated() instead of false if check is invalid

* Add test for <1.17 as well

---------

Co-authored-by: sovdee <[email protected]>
  • Loading branch information
TenFont and sovdeeth authored Sep 22, 2024
1 parent 3e3f0a9 commit 9801329
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/conditions/CondIsWithin.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public boolean check(Event event) {
Location one = loc1.getSingle(event);
Location two = loc2.getSingle(event);
if (one == null || two == null || one.getWorld() != two.getWorld())
return false;
return isNegated();
AABB box = new AABB(one, two);
return locsToCheck.check(event, box::contains, isNegated());
}

// else, within an entity/block/chunk/world
Object area = this.area.getSingle(event);
if (area == null)
return false;
return isNegated();

// Entities
if (area instanceof Entity) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/skript/tests/syntaxes/conditions/CondIsWithin.sk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ test "within condition" when running minecraft "1.17":
set {_loc2} to location(20, 20, 20, "world")
assert location(10, 10, 10, "world") is within {_loc1} and {_loc2} with "failed within two locs"
assert location(10, -10, 10, "world") is not within {_loc1} and {_loc2} with "failed within two locs"
assert location(0, 0, 0, "world") is not within {_none} and {_none} with "failed within two locs"

# chunks
set {_chunk1} to chunk at {_loc1}
Expand Down Expand Up @@ -37,6 +38,7 @@ test "within condition" when running below minecraft "1.17":
set {_loc2} to location(20, 20, 20, "world")
assert location(10, 10, 10, "world") is within {_loc1} and {_loc2} with "failed within two locs"
assert location(10, -10, 10, "world") is not within {_loc1} and {_loc2} with "failed within two locs"
assert location(0, 0, 0, "world") is not within {_none} and {_none} with "failed within two locs"

# chunks
set {_chunk1} to chunk at {_loc1}
Expand Down

0 comments on commit 9801329

Please sign in to comment.