1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

get faction of player

Discussion in 'Development' started by Th3Ang3lo, Jan 6, 2019.

  1. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    Hi everyone, I'm doing a McMMO plugin, but in spades ability, the same faction player can advance levels of swords by beating a member of the same faction, how do I block this using FactionPro functions?

    I used this:

    Code:
    Swords.php
    PHP:
    public function onDamage(EntityDamageEvent $ev){
            if(!
    $ev instanceof EntityDamageByEntityEvent){
                return;
            }
       
            if(
    $ev instanceof EntityDamageByEntityEvent){
                if(
    $ev->getDamager() instanceof Player){
                    if(
    $ev->isCancelled()){
                        return;
                    }
       
                    
    $entity $ev->getEntity()->getName();
                    
    $player $ev->getDamager()->getName();
       
                    
    $faction $this->pl->getServer()->getPluginManager()->getPlugin("FactionsPro");
                    if(
    $faction->getPlayerFaction($entity) == $faction->getPlayerFaction($player)){
                        
    $this->pl->getServer()->getLogger()->info("CONDITION TEST. The two players are from the same faction");
                        return;
                    }
       
                }
            }
        }
    but nothing happens... Not even a mistake...
     
  2. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Try with this inside your if()
    PHP:
    $faction->sameFaction($entity$player);
    Also lines 3, 4 and 5 don't make sense if you're going to check the same thing below.
     
    corytortoise likes this.
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Tip: you no longer need to check $event instanceof EntityDamageByEntityEvent. You could directly put EntityDamageByEntityEvent in the parameter type.
    (This has actually been fixed for ages)
     
    Muqsit likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.