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

Solved Damage by explosion

Discussion in 'Development' started by ItzAribie, Dec 8, 2017.

  1. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    Hello,
    I would like to know how to cancel a damage on a player who place a TNT and the players approximate receive a damage.


    Here my code but I don't know why the explosion doesnt cancelled.
    PHP:
    public $placer = [];

        public function 
    onBlockPlace(BlockPlaceEvent $e)
        {
            
    $p $e->getPlayer();
            
    $b $e->getBlock();

             if(
    $b->getId() === 46){
               
    $this->placer[$p->getName()] = $p->getName();

            }
        }

        public function 
    onHit(EntityDamageEvent $e)
        {
            
    $victim $e->getEntity();

            if (!
    $victim instanceof Player) {
                return;
            }

            if (
    $e instanceof EntityDamageByChildEntityEvent) {

                if(
    $e->getCause() === && isset($this->placer[$victim->getName()])) {
                        
    $e->setCancelled();
                 }
             }
         }
     
    Last edited: Dec 8, 2017
  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.