pocketmine\Player::attack PHP Method

attack() public method

public attack ( $damage, EntityDamageEvent $source )
$source pocketmine\event\entity\EntityDamageEvent
    public function attack($damage, EntityDamageEvent $source)
    {
        if (!$this->isAlive()) {
            return;
        }
        if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
            $source->setCancelled();
        } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
            $source->setCancelled();
        }
        parent::attack($damage, $source);
        if ($source->isCancelled()) {
            return;
        } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
            $pk = new EntityEventPacket();
            $pk->eid = 0;
            $pk->event = EntityEventPacket::HURT_ANIMATION;
            $this->dataPacket($pk);
            if ($this->isSurvival()) {
                $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
            }
        }
    }
Player