Listen, since you're my little bro i feel more responsible than just a blog viewer.
So, your girlfriend have feeling/interest for your friend, that's nothing that you or anybody could do anything about it. People meet each other and relations begins. but it's nothing that you could own someone and protect from being robbed!
A girl is a person, she decides, she thinks and she feels. Mostly all nonsenses about stealing someones heart and things like that ends up in total bull****. If not your friend other guy from next door or class could be a the one with her now! Don't think of it as a bad or good. There's trauma specially when people think they got stabbed from behind, but remember little noble, Girls and mainly people are not property to oblige them and seal them as a contract of ownership.
Try be more confident but do not hesitate to tell your friend or your ex that you are feeling bad about it and you expected more from your friends, don't curse them!