how can i stop the ender dragon from changing phase

I'm trying to code a somewhat custom dragon fight using the dragon stages but the problem is the entire dragon just changes it's phase immediately so I am wondering if anyone knows how to stop it from changing its phases so I can have control over what it does

Continue to help post