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

Checking the player that threw an ender pearl.

Discussion in 'Development' started by Todo56, Nov 20, 2019.

  1. Todo56

    Todo56 Silverfish

    Messages:
    17
    GitHub:
    todo56
    I'm making an area plugin which shouldn't allow players that are on combat to throw ender pearls at a designated area. I've thought about using EntityMotionEvent but I'm not sure how to get the player.
     
  2. Emis02

    Emis02 Spider Jockey

    Messages:
    34
    GitHub:
    RubyTemple
    Code:
    public function enderpearlLaunchEvent(ProjectileLaunchEvent $event){
            $entity = $event->getEntity();
            if ($entity instanceof EnderPearl){
                $event->setCancelled(true);
            }
        }
    easy man
     
  3. Todo56

    Todo56 Silverfish

    Messages:
    17
    GitHub:
    todo56
    I want to get the player though.
     
  4. Emis02

    Emis02 Spider Jockey

    Messages:
    34
    GitHub:
    RubyTemple
    PHP:
    public function enderpearlLauncheEvent(ProjectileLaunchEvent $event){
            
    $entity $event->getEntity();
            if (
    $entity instanceof EnderPearl){
                
    $player $entity->getOwningEntity(); //this can return null, check that isn't null before using it
                
    if ($player instanceof Player and $player !== null) {
                    
    $this->getLogger()->info("This player have launch and enderpearl: " $player->getName());
                }
            }
        }
    use getOwningEntity() and getTargetEntity()
     
    Muqsit likes this.
  5. Emis02

    Emis02 Spider Jockey

    Messages:
    34
    GitHub:
    RubyTemple
    it's ok?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Btw $player instanceof Player implies $player is not null so the $player !== null check is not necessary.
     
    HimbeersaftLP likes this.
  7. Emis02

    Emis02 Spider Jockey

    Messages:
    34
    GitHub:
    RubyTemple
    oh ok
     
  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.