myPlayer().isUnderAttack(); // // this is the boolean to check whether it is under attack, don't forget to null check!
NPC npc = getNpcs().closest("Goblin");
npc.isUnderAttack(); // this is the boolean to check whether it is under attack, don't forget to null check!
Please familiarise yourself with the API.
Precise.