if (myPlayer().isUnderAttack()) {
lastAttack = System.currentTimeMillis();
//KEEP AFKING
} else if (System.currentTimeMillis() > (lastAttack + resetTime) && !myPlayer().isUnderAttack()) {
//RESET PLAYER
}
Reset time is the amount of time the player should not be in combat in milliseconds, which indicates whether we are still aggro or not. In your case, I suggest putting it at around 20000 milliseconds = 20 seconds.