How did you stop being someone’s doormat?

I’ve been on and off with my ex for like a year and a half. We were official twice during this time and in between those times we didn’t have a label. He just goes ghost and then has come back. He went ghost on me last week, I tried calling and texting but he didn’t answer. He acts like one minute he’s so interested in talking to me then the next he isn’t. When he comes back he acts like nothing ever happened. I know I shouldn’t continue to happen but I find it hard. Some weird reason I get excited that he decided to talk to me again. For anyone that’s been in this situation, what made you finally decide to stop being someone’s doormat? What happened when you finally went through with it?