Break the habit.
Probably the best thing you can do when you’ve been selfish is admit it. It’s not the easiest thing in the world, but it’s important. When we admit that we’ve made a mistake or that something might have been selfish, it creates a path forward where we should change it.
For many of us, we prefer to hide behind pride and ignorance. We’d rather not know we were wrong or we’d rather defend it and pretend it wasn’t wrong in the first place. There is no healing and no growth in this. The best thing you can do if you find yourself being selfish is simply admit that the action was just that, selfish. Tell the person you hurt, tell people you trust, be honest about it, and ask for their help in keeping you accountable. There is nothing wrong with asking for help. There is so much wrong with needing help and refusing to get it.