public class CuttingHandler extends Task {
@Override
public boolean validate() {
Area treeArea = new Area.Rectangular(new Coordinate(3175, 3373, 0), new Coordinate(3154, 3422, 0));
return !Inventory.isFull() && treeArea.contains(Players.getLocal());
}
@Override
public void execute() {
Coordinate treesCoord = new Coordinate(3167, 3410, 0);
GameObject tree = GameObjects.newQuery().names("Tree").filter(obj -> obj.isValid()).results().nearest();
Area treeArea = new Area.Rectangular(new Coordinate(3175, 3373, 0), new Coordinate(3154, 3422, 0));
if(treeArea.contains(Players.getLocal())) {
if (tree != null) {
if(treeArea.contains(tree)) {
if (tree.isVisible()) {
if (Players.getLocal().getAnimationId() == -1 && !Players.getLocal().isMoving()) {
if (tree.interact("Chop down", "Tree")) {
Execution.delayUntil(() -> Players.getLocal().getAnimationId() == -1, 5000);
}
} else {
Execution.delayUntil(() -> Players.getLocal().getAnimationId() == -1, 5000);
}
} else {
Camera.turnTo(tree, Random.nextDouble(0.300, 0.500));
}
}else{
completeWalking(treesCoord);
}
}
}
}
public static boolean completeWalking(Locatable location) {
WebPath q = Traversal.getDefaultWeb().getPathBuilder().buildTo(location);
if (q != null) {
q.step();
} else {
RegionPath q2 = RegionPath.buildTo(location);
if (q2 != null) {
q2.step();
} else {
BresenhamPath q3 = BresenhamPath.buildTo(location);
if (q3 != null) {
q3.step();
}
}
}
return false;
}
}