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

DeathEvent not working

Comments in 'Plugin Development' started by Jaydenb1321, May 18, 2016.

  1. Jaydenb1321
    Offline

    Jaydenb1321 New Member

    Joined:
    Aug 16, 2014
    Posts:
    45
    Minecraft User:
    ItzBulkDev
    Ok so i have a plugin, and when the player dies it adds points and other functions (which are hidden) but anyways none of my code works on PlayerDeathEvent and i suspect it is due to
    PHP:
    if($event->getEntity()->getPlayer()->getLevel()->getName() == "SwordGame"){
    but can anyone find the error. The console shows now error message but it simply doesnt work.
    PHP:
    public function onDeath(PlayerDeathEvent $event){
      
    $cause $event->getEntity()->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
            if(
    $event->getEntity()->getPlayer()->getLevel()->getName() == "SwordGame"){
                
    $player2 $event->getEntity();
                
    $killer $cause->getDamager();
                
    $player $cause->getDamager();
                
    $kname $killer->getName();
                
    $pname $player2->getName();
                if(
    $killer instanceof Player) {
                    
    $player->sendMessage(TextFormat::GREEN."+1 Point! (Killed " $pname "!)");
                    
    $player2->sendMessage(TextFormat::RED."-1 Point! (Killed by " $kname ")!");
    }
    }
    }
    }
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    1. Check if you have registered your events.
    2. Check if you've implemented Listener.
  3. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    The Entity class does not have a getPlayer() function.
    Legoboy0215 likes this.
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    PHP:
    if($event->getEntity()->getLevel()->getName() == "SwordGame"){
    PHP:
    public function onDeath(PlayerDeathEvent $event){
      
    $cause $event->getEntity()->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
            if(
    $event->getEntity()->getLevel()->getName() == "SwordGame"){
                
    $player2 $event->getEntity();
                
    $killer $cause->getDamager();
                
    $player $cause->getDamager();//Why is $player the same as the $killer?
                
    $kname $killer->getName();
                
    $pname $player2->getName();
                if(
    $killer instanceof Player) {
                    
    $player->sendMessage(TextFormat::GREEN."+1 Point! (Killed " $pname "!)");
                    
    $player2->sendMessage(TextFormat::RED."-1 Point! (Killed by " $kname ")!");
    }
    }
    }
    }

Share This Page

Advertisement