Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to fix the crash? EntityDamageEvent

Comments in 'Plugin Development' started by Eddir, Jul 18, 2015.

  1. Eddir
    Offline

    Eddir New Member

    Joined:
    Jan 23, 2015
    Posts:
    5
    Minecraft User:
    Eddir
    I have some errors when I use this plugin. He must kill the player if they attacked with bone.

    PHP:
     public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
    public function 
    onHurt(EntityDamageEvent $e){
    $entity $e->getEntity();
    if(
    $entity instanceof Player){
    if(
    $e instanceof EntityDamageByEntityEvent){
    $killer $e->getDamager()->getPlayer()->getName();
    $cause $e->getEntity()->getPlayer()->getName();
    if(
    $e->getDamager()->getInventory()->getItemInHand()->getId() == 352){
        
    $e->getEntity()->getPlayer()->setHealth($e->getEntity()->getPlayer()->getHealth() - 20);
         
    $e->getDamager()->getInventory()->removeItem(Item::get(35201));
        }
        }
        }
        }
    Crash:

    Code:
    Error: Call to undefined method pocketmine\entity\PrimedTNT::getPlayer()
    File: /Bone_v2.phar/src/eddir/Bone
    Line: 39
    Type: E_ERROR
    How to fix it?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    if($e->getDamager()->getInventory()->getItemInHand()->getId() == 352){
    $e->getEntity()->getPlayer()->kill(); // use kill()
    $e->getDamager()->getInventory()->removeItem(Item::get(35201));
    }
    Umm there's more wrong in it :D
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't know where you got the getPlayer. It is simply useless, unnecessary and wrong. And $killer anas $entity are unussed.

    Please, we are not nannies. We are not here to hold your finger and teach you to type button by button. Please understand what you are doing when you do it.
  4. Eddir
    Offline

    Eddir New Member

    Joined:
    Jan 23, 2015
    Posts:
    5
    Minecraft User:
    Eddir
    Thanks. I was able to find the error. Sorry to trouble you.

Share This Page

Advertisement