This is very useful, great work! I think you could probably simplify it a bit, and remove some of the dependencies like this:
import java.awt.Polygon;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;
public class PolygonArea
{
Polygon polygon;
PolygonArea(Position... positions)
{
polygon = new Polygon();
addPositions(positions);
}
public boolean containsEntity(Entity e)
{
return polygon.contains(e.getX(), e.getY());
}
public void addPositions(Position... positions)
{
for (Position pos : positions)
{
polygon.addPoint(pos.getX(), pos.getY());
}
}
}
How to use
PolygonArea polygonArea = new PolygonArea(positionsArray);
Check for entities in the area with this (NPC, Player, GroundItems, etc):
if (polygonArea.containsEntity(entity))
{
//do method
}