Check if player is in ally territory (Factions)

Discussion in 'Plugin Development' started by 808sFinest, Apr 12, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    808sFinest

    Hello! Does anybody know how to check if player is in an ally territory?
     
  2. Offline

    DoggyCode™

    Code:
    //Get a Player object.
    Player p = (Player)sender;
    String uuid = p.getUniqueId().toString();
    
    //make it MPlayer
    MPlayer mplayer;
    //you can use all these methods to get the player
    mplayer=MPlayer.get(uuid);
    mplayer=MPlayer.get(UUID.fromString(uuid));
    mplayer=MPlayer.get(sender);
    mplayer=MPlayer.get(p);
    
    //Getting the faction
    Faction fac = null;
    fac = mplayer.getFaction();
    
    //there's a method for getting the land which the player is standing in, then getting the lands owner. I'm on my iPad rn and can't find it
    Faction inTerritory = the faction that owns the land which the player is standing in;
    Rel relation = getRelationOfThatToMe(inTerritory, fac);
    if(relation==Rel.ALLY){
      //player is in allied territory
    } else {
      //player is not in allied territory
    }
    
    
    
    public static Rel getRelationOfThatToMe(Faction thatFaction, Faction myFaction, boolean ignorePeaceful)
    {
      Rel ret = null;
    
      if (myFaction == null) return Rel.NEUTRAL; // ERROR
    
      if (thatFaction == null) return Rel.NEUTRAL; // ERROR
      // The faction with the lowest wish "wins"
      if (thatFaction.getRelationWish(myFaction).isLessThan(myFaction.getRelationWish(thatFaction)))
      {
        ret = thatFaction.getRelationWish(myFaction);
      }
      else
      {
      ret = myFaction.getRelationWish(thatFaction);
      }
      if (myFaction.equals(thatFaction))
      {
        ret = Rel.MEMBER;
        // Do officer and leader check
        //P.p.log("getRelationOfThatToMe the factions are the same for "+that.getClass().getSimpleName()+" and observer "+me.getClass().getSimpleName());
        if (that instanceof MPlayer)
        {
          ret = ((MPlayer)that).getRole();
          //P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
        }
    }
    else if (!ignorePeaceful && (thatFaction.getFlag(MFlag.getFlagPeaceful()) || myFaction.getFlag(MFlag.getFlagPeaceful())))
    {
      ret = Rel.TRUCE;
    }
    return ret;
    }
    You might have to format it.
     
    Last edited: Apr 13, 2016
  3. Offline

    mcdorli

    Please don't spoonfeed.

    There are multiple factions plugins, wich one do you need? What have you tried?
     
  4. Offline

    808sFinest

  5. Offline

    DoggyCode™

Thread Status:
Not open for further replies.

Share This Page