getRelationTo factions

Discussion in 'Spigot Plugin Development' started by iNoXs, May 22, 2016.

  1. Hi !
    i try to get the relation of a player faction to another faction but i don't know how to do :/

    here is my code

    MPlayer up =MPlayer.get(sender);

    Faction faction =???;




    if(faction.getRelationTo(up)==Rel.ENEMY){
    NameTag.OnTag((Player) sender,"§C[Enemy]");
    }
     
  2. up.getFaction()?
     
    • Agree Agree x 1
  3. and after :
    MPlayer up = MPlayer.get(sender);

    Faction getfaction = up.getFaction();



    if(getfaction.getRelationTo(up) == Rel.ENEMY){
    NameTag.SetTag((Player) sender, "§C[Enemy]");
    }
     
  4. Code (Text):
            MPlayer p1 = MPlayer.get(player1);
            MPlayer p2 = MPlayer.get(player2);

            Faction faction1 = p1.getFaction();
            Faction faction2 = p2.getFaction();

            if(faction1.getRelationTo(faction2) == Rel.ENEMY){
                // set the nametage for these two players
            }
     
  5. And if i want player2 to be all player connected to the server ?
     
  6. Then loop trough all online players (except the player itself) and run this code for every player.
     
  7. Code (Text):
    for(Player player2 : Bukkit.getOnlinePlayers()){
                   MPlayer p2 = MPlayer.get(player2);
                   Faction faction2 = p2.getFaction();
                    MPlayer p1 = MPlayer.get(player1);
                    Faction faction1 = p1.getFaction();
                    if(faction1.getRelationTo(faction2) == Rel.ENEMY){
                               
                        NameTag.SetTag(player2, "§c Enemy ");
                    }
                    if(faction1.getRelationTo(faction2) == Rel.NEUTRAL){
                       
                        NameTag.SetTag(player2, "§f Neutral ");
                    }
                    if(faction1.getRelationTo(faction2) == Rel.ALLY){
                       
                        NameTag.SetTag(player2, "§a Ally ");
                    }
                   
                   
                    }
           
    Work but the player2 prefix return to the Faction1 relation to faction2
     
  8. you should check your if statements.
     
  9. idk how to fix :/ im stuck
     
  10. That should not be done... ever...

    Can you first tell us what you're trying to do exactly? Make a command that checks for the factions relations? Something completely irrelevant?
     
  11. If you're making a command I'm assuming you're going to input the faction names.
    If so you can use the FactionColl utility class.
    Code (Java):
    Faction faction = FactionColl.get().getByName("factionName");
     
  12. i don't want to get by name i want to get all the player faction connected and after put a prefix [Ally], [Enemy] ...
     
  13. Quite easy to achieve. The FactionColl class provides a method for fetching all factions that are currently on the server.
    Code (Java):
    FactionColl.get().getAll()
     
  14. Thx i will try :)