You could save the name of each player in separate arrays, and on EntityDamageByEntityEvent, check if both the Entity's and the Damager's names are in the same array. If they are, you can cancel the event.
First you have to define "team". How is a team created? Is it temporary? Did you implement the team system already?