api: Add contains methods to WorldPoint and WorldArea
This commit is contained in:
committed by
Owain van Brakel
parent
3a64e1063e
commit
c08c6d80e8
@@ -160,6 +160,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>
|
||||
|
||||
@@ -557,4 +557,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user