So, I'm trying to do a teams plugin, where each team has a player1 and player2. Now I wanted to add friendyfire using the EntityDamageByEntityEvent, but either my code doesn't work, or the event doesn't get activated. I'm pretty new to Plugins, so it could be that my code is a little bit stupid. Btw, "teams2" is a ArrayList with "Team" Objects in it, each contains player1, player2 and the teamname.
This is the function:
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (((event.getEntity() instanceof Player)) && ((event.getDamager() instanceof Player))) {
Player player = (Player)event.getEntity();
Player damager = (Player)event.getDamager();
for(int i = 0; i < teams2.size(); i++){
if((teams2.get(i).player1 == player || teams2.get(i).player2 == player) && (teams2.get(i).player1 == damager || teams2.get(i).player2 == damager)){
event.setCancelled(true);
}
}
}
else if (((event.getEntity() instanceof Arrow)) && ((event.getDamager() instanceof Player))) {
Entity arrow = event.getEntity();
if ((((Projectile)arrow).getShooter() instanceof Player)) {
Player player = (Player)arrow;
Player damager = (Player)event.getDamager();
for(int i = 0; i < teams2.size(); i++){
if((teams2.get(i).player1 == player || teams2.get(i).player2 == player) && (teams2.get(i).player1 == damager || teams2.get(i).player2 == damager)){
event.setCancelled(true);
}
}
}
}
}
It should cancel the event, so that players from the same team can't attack each others, but thats not the case. Why? You can also suggest other ways to create a FriendlyFire function.