I've tested this and it works
private void dealWithRandomEvent() {
NPC npc = npcs().query().results().nearest();
if (npc == null)
return;
if (!npc.hasAction("Dismiss"))
return;
mouse().moveRandomly(random(500,4000));
npc.interact("Dismiss");
System.out.println(npc.getName() + " dismissed");
mouse().moveOffScreen();
}