I’m unclear what you are asking for, but from what I can gather is that you want to logout if a boss exists and you’re not under attack, wait, then login again?
For login I would use a custom login handler to handle the event. There’s an example somewhere around here, just do a quick search.
For the wait set a timer. You can store System.currentTimeMillis on logout. Then on the loop check for the required gap. If ( System.currentTimeMillis - storedTime > waitTime ) then login.