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

Check if Event cancelled

Discussion in 'Plugin Help' started by Infernus101, Dec 3, 2016.

  1. Infernus101

    Infernus101 Witch

    Messages:
    54
    GitHub:
    infernus102
    PHP:
      foreach($pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius 5), $pos->getFloorY() - $radius$pos->getFloorZ() - $radius$pos->getFloorX() + $radius$pos->getFloorY() + $radius$pos->getFloorZ() + $radius), $pos) as $e){
            
                
    $e->attack(0, new EntityDamageEvent($posEntityDamageEvent::CAUSE_MAGIC$damage));
              
            }
    How do i make this to like only damage the Entity if the EntityDamageEvent isn't cancelled?
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Check if it has besn cancelled by EventObject->isCancelled()
     
    Infernus101 likes this.
  3. Infernus101

    Infernus101 Witch

    Messages:
    54
    GitHub:
    infernus102
    Can you recode and post please?
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
      foreach($pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius 5), $pos->getFloorY() - $radius$pos->getFloorZ() - $radius$pos->getFloorX() + $radius$pos->getFloorY() + $radius$pos->getFloorZ() + $radius), $pos) as $e){
          if(!
    $event->isCancelled()){
                
    $e->attack(0, new EntityDamageEvent($posEntityDamageEvent::CAUSE_MAGIC$damage));
          }
      }
     
    Infernus101 likes this.
  5. Infernus101

    Infernus101 Witch

    Messages:
    54
    GitHub:
    infernus102
    PHP:
          public function strikeLightning(Position $posint $damage 0){
            
    $pk $this->lightning($pos);
            foreach(
    $pos->getLevel()->getPlayers() as $p){
                
    $p->dataPacket($pk);
            }
            if(!
    $pos instanceof Entity and !($pos $this->createTNT($posnullfalse))){
                return;
            }
            foreach(
    $pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius 5), $pos->getFloorY() - $radius$pos->getFloorZ() - $radius$pos->getFloorX() + $radius$pos->getFloorY() + $radius$pos->getFloorZ() + $radius), $pos) as $e){
           
                
    $e->attack(0, new EntityDamageEvent($posEntityDamageEvent::CAUSE_MAGIC$damage));
             
            }
        }
    $event isn't declared.
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    I don't think you can change that like that. You might have to add some code in a listener to mimic what you want. For example: on entity damage event cancel it if its cause is CAUSE_MAGIC in specified worlds / locations.
     
    Infernus101 likes this.
  7. Infernus101

    Infernus101 Witch

    Messages:
    54
    GitHub:
    infernus102
    Oh, okay. But still they get hurt in protected areas even in the allowed worlds, but okay!
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    There does not exist a method EventObject->isCancelled(). There only exists the method Event->isCancelled().
     
    Sandertv 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.