You will need to be aware of the effect MDMA can have on the stomach. Peptic ulcers can take a long time to completely heal, particularly if aggravated by acidic compounds, or those that produce acidic conditions.
MDMA is a ring substituted methamphetamine, and although classified as a weak base, it comes in an acid salt form (as it is water soluble). Consumed orally, the effects of Meth and MDMA can result in a raising of stomach acid (lowering of the pH). If there is an ulcer present, this stomach acid will burn and irritate. A pill or powder, if bombed or parachuted (wrapped in cig paper and swallowed), may also cause the ulcer to be irritated, especially if it adheres to the walls of the rugae (small folds that line the inside of the stomach when it is empty).
My advice is to read up on the physiology of the stomach, and try to discover which part of your lifestyle has caused, or adversely affected your condition. The first thing to do is to heal the ulcer, which as said can take quite a while. That means minimising high acid foods and drugs like MDMA. Should you decide to take MDMA again, I would suggest taking it as a drink, with or after food. The tablet / or powder can be crushed and the actives dissolved in water. This should maximise the surface area contact in the stomach, and minimise any concentrated "pockets", but it may not stop the acid conditions which can follow absorption.
A number of things can cause and aggravate an ulcer. Smoking, alcohol, fatty or spicy foods etc. should all be avoided. In fact anything that causes bloating or pain/discomfort. As you've said, you're only 22, so you've plenty of time left to party. Just make sure you get well first, and accept the fact that partying - at least for awhile - may have to mean limiting some treats and avoiding others altogether.
Good Luck