api: Add contains methods to WorldPoint and WorldArea

This commit is contained in:
pwatts6060
2021-09-21 00:55:34 -07:00
committed by Jordan Atwood
parent 86cda7de0b
commit 9c7fade732
3 changed files with 57 additions and 1 deletions

View File

@@ -151,6 +151,26 @@ public class WorldArea
return distanceTo2D(new WorldArea(other, 1, 1));
}
/**
* Checks whether a tile is contained within the area and in the same plane.
*
* @return {@code true} if the tile is contained within the bounds of this area, {@code false} otherwise.
*/
public boolean contains(WorldPoint worldPoint)
{
return distanceTo(worldPoint) == 0;
}
/**
* Checks whether a tile is contained within the area while ignoring the plane.
*
* @return {@code true} if the tile is contained within the bounds of this area regardless of plane, {@code false} otherwise.
*/
public boolean contains2D(WorldPoint worldPoint)
{
return distanceTo2D(worldPoint) == 0;
}
/**
* Checks whether this area is within melee distance of another.
* <p>

View File

@@ -406,4 +406,40 @@ public class WorldPoint
}
return worldPoint;
}
/**
* Checks whether this tile is located within any of the given areas.
*
* @param worldAreas areas to check within
* @return {@code true} if any area contains this point, {@code false} otherwise.
*/
public boolean isInArea(WorldArea... worldAreas)
{
for (WorldArea area : worldAreas)
{
if (area.contains(this))
{
return true;
}
}
return false;
}
/**
* Checks whether this tile is located within any of the given areas, disregarding any plane differences.
*
* @param worldAreas areas to check within
* @return {@code true} if any area contains this point, {@code false} otherwise.
*/
public boolean isInArea2D(WorldArea... worldAreas)
{
for (WorldArea area : worldAreas)
{
if (area.contains2D(this))
{
return true;
}
}
return false;
}
}

View File

@@ -248,7 +248,7 @@ public class NpcAggroAreaPlugin extends Plugin
private static boolean isInWilderness(WorldPoint location)
{
return WILDERNESS_ABOVE_GROUND.distanceTo2D(location) == 0 || WILDERNESS_UNDERGROUND.distanceTo2D(location) == 0;
return location.isInArea2D(WILDERNESS_ABOVE_GROUND, WILDERNESS_UNDERGROUND);
}
private boolean isNpcMatch(NPC npc)