Better gang allies handling

Discussion in 'Grand Theft Minecart' started by STEngineer, Jun 19, 2019.

  1. STEngineer

    STEngineer Hobo

    Joined:
    May 21, 2019
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    So I can damage and be damaged by members of an allied gang of an allied gang of my gang, etc. It would be better I couldn't damage and be damaged by members of an allied gang of an allied gang of my gang, etc..
    Something like that in your gang class:
    Code:
    public List<UUID> getAllies() {
        List<UUID> allies = new ArrayList<>();
        allies.addAll(getMembers());
        getAlliedGangs().forEach(g -> {
            g.getAllies().forEach(ap -> {
                if(!allies.contains(ap)) {
                    allies.add(ap);
                }
            });
        });
        return allies;
    }
    public boolean isAlly(UUID player) {
        return getAllies().contains(player);
    }
    And then in your EntityDamageByEntityEvent listener get damager's gang and do if(<gang>.isAlly(<damaged entity>.getUniqueId())) cancel the event and do your things like sending messages, etc.
    NOTE: I didn't see your gang class, so this code may be wrong.
    NOTE: You need to prevent cycling allied gangs.
     
    Last edited: Jun 20, 2019