diff --git a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java index 0591480e..c05b96e8 100644 --- a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java +++ b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java @@ -102,6 +102,7 @@ public boolean contains(Vector pt) { int xOld, zOld; int x1, z1; int x2, z2; + long crossproduct; int i; xOld = points.get(npoints - 1).getBlockX(); @@ -125,10 +126,14 @@ public boolean contains(Vector pt) { z1 = zNew; z2 = zOld; } - if ((xNew < targetX) == (targetX <= xOld) - && ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1) - * (long) (targetX - x1)) { - inside = !inside; + if (x1 <= targetX && targetX <= x2) { + crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1) + - ((long) z2 - (long) z1) * (long) (targetX - x1); + if (crossproduct == 0) { + if ((z1 <= targetZ) == (targetZ <= z2)) return true; // on edge + } else if (crossproduct < 0 && (x1 != targetX)) { + inside = !inside; + } } xOld = xNew; zOld = zNew;