Anyone who could potentially be harmed by the registration of a trademark can oppose its registration. Therefore, X can prevent the registration of a mark by Y, even if X has not filed his own registration of the mark. It will usually be the owner of a mark, that competes with the mark proposed for registration, who will file a written opposition, however.
The opposition filing must be done within 30 days of the Official Gazette's publication of the proposed mark, although if it is hard to meet the 30 day mark, a 30-day extension can be requested (and then another 60-day one after that, if good cause can be shown for the extension).
Even if the mark has passed the 30-day publication date and has already been placed on the Principal Register, all is not lost for the owner of a competing mark. A cancellation petition can be filed (if done within 5 years or if other conditions apply).
When marks are not distinctive or unique enough for placement on the Principal Register (a descriptive mark, for example), then the mark can be placed on the Supplemental Register. Again, marks placed on the Supplemental Register can also be challenged, by applying for a cancellation of the registration.
Disputes over trademarks will be heard in a proceeding before the Trademark Trial and Appeal Board. The dispute can be resolved with the cancellation of a mark, a USPTO refusal to register one or both of the marks, restrictions on the use of one or both marks, dual registrations of the mark allowed with conditions and restrictions on uses, or registration of one or the other of the marks.
In other words, there are several different ways this can play out, oohlalaw. I am glad you have an attorney in your area to consult with.