We all struggle to stop bad habits like smoking, or eating or drinking too much.
A crucial component in breaking a habit is to completely avoid situations where you will be tempted.
Identify any people, places, times and situations which are likely to lead you to fall off the wagon. Then, make plans.
Where possible, arrange to stay away from all of these tempting situations for twenty-one days. Organise yourself to be doing something else or to be somewhere else instead.
As you persist, you will find the habit fades and your self-discipline strengthens.
As the desire weakens you can slowly give yourself more freedom in this regard.
If you fall off the wagon, you might have to consider whether it is more important for you to break the habit, or engage in the activity.
[This is from 52 Secrets of Psychology, by Dr Chris Day. A link is on this homepage of the website.]