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

Solved Get killer of PlayerDeathEvent???

Comments in 'Plugin Development' started by Legoboy0215, Aug 9, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    What is the right way to do this???
    I tried this:
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
    if(
    $cause instanceof EntityDamageByEntityEvent){
                    
    $killer $cause->getDamager();
                    if(
    $killer instanceof Player){
                        
    $name $killer->getName();
                        
    $this->getServer()->broadcastMessage($name);
                   }
                }
    But nothing happens.
    Last edited: Aug 9, 2015
  2. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
                    if(
    $cause instanceof EntityDamageEntityEvent){
                    
    $killer $cause->getDamager();
                    if(
    $killer instanceof Player){
                        
    $name $killer->getName();
                        
    $this->getServer()->broadcastMessage($name);
                   }
                }
    ^^^^ this shall do

    EntityDamageByEntity is wrong ( PeMapModder : Actually, if you checked it is EntityDamageByEntityEvent, it must be an EntityDamageEvent. No need to check both. )
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    No Wonder Why When I Tried This Is Crashed When I Killed A Player :p
    iDirtPlayzMC likes this.
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    xP
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    NVM. I figured it out. It was not the thing you said idirtplayz. It was that I forgot to import EntityDamageByEntityEvent. :)
    CraftYourBukkit likes this.
  6. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    ow..
    Legoboy0215 likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What? It is EntityDamageByEntityEvent not EntityDagameEntityEvent
    And you need to check it is EntityDamageByEntityEvent so that you can use the damager functions. And well, we check EntityDamageEvent because we want to handle non entity related deaths tkl.

Share This Page

Advertisement