I'm Lucy, and I'd be happy to answer your questions today. I'm very sorry to hear that this happened.
It is actually illegal for a landlord to retaliate against a tenant for calling 311 in good faith. NY Real Prop. Laws, Section 223-b. You have a right to sue the landlord for any damages you incur as a result of that illegal behavior. But your damages are limited by the fact that you're not supposed to be living there. The ordinary remedy is that the tenant is allowed to stay, and that can't happen here.
The biggest problem that you're facing is that the apartment is illegal. That means, if the landlord sues for eviction, a judge has no legal authority to allow you to stay. The place is illegal. You're not supposed to be living there. If the inspector had been allowed into the apartment, they'd have said as much. And that means there's unfortunately no law that would allow you to avoid moving out. You do have a right to force her to go to court to complete the eviction, and you can sue for a refund of rent for each day the property was infested and every time the property flooded for the past three years. The statute of limitations for breach of contract is 6 years, so you're within that time period.
Also note that since it's illegal for you to be there, the landlord could not sue you for any unpaid rent between now and when you move out. And you can call 311 back and let them in. They can take fine the landlord for renting an illegal unit.
I apologize that this was probably not the Answer you were hoping to receive. However, it would be unfair to you and unprofessional of me were I to provide you with anything less than truthful and honest information. I hope you understand. Please rate my answer positively to ensure I am paid for the time I spent answering your question. If you are on a mobile device, you may need to scroll to the right. Thank you.