if (guard != null && guard.isAttackable() && !myPlayer().isUnderAttack())
return State.KILL;
You need more checks other than "guard != null" if you want to fight NPC.
As IHB said, you should put a sleep after interaction; a conditional sleep.
if(guard != null){
if(guard.interact("Attack")) {
log("Status: Attacking...");
new ConditionalSleep(4000, 500) {
@Override
public boolean condition() throws InterruptedException {
return api.myPlayer().isInteracting(guard);
}
}.sleep();
}
}
It will check the condition() every 500 ms and wait maximum 4000 ms before executing the interaction again.