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

Detect when player get hurt

Discussion in 'Development' started by indiemaker, Jun 11, 2020.

  1. indiemaker

    indiemaker Creeper

    Messages:
    1
    Hi there! I need a way to detect when the player get hurt.

    (I'm very new to plugins, i started yesterday.)
     
  2. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    You can use the events EntityDamageEvent or EntityDamageByEntityEvent to detect the entity that receives the damage.
     
    Emirhan Akpınar likes this.
  3. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    /** @var event EntityDamageEvent */

    public function onEntityDamage(EntityDamageEvent $event): void {
      
    $entity $event->getEntity();
      if (
    $entity instanceof Player) {
        
    // When player get hurt / damage.
      
    }
      if (
    $event instanceof EntityDamageByEntityEvent) {
        if ((
    $damager $event->getDamager()) instanceof Player) {
          
    // When player get hurt / damage from any player.
        
    }
      }
    }
     
  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.