Hi, I am amateur in PMMP API can anyone help me with this: I am editing Kill Money plugin for my server I have a problem with it Kill Money only count kill by PvP but I need it for PvP and Projectiles like Snowball together I know l should use DeathEvent but I don't know which event help me with find that event and use it PHP: public function onPlayerDeath(PlayerDeathEvent $event) : void{ $victim = $event->getPlayer(); if($victim->getLastDamageCause() instanceof EntityDamageByChildEntityEvent){ if($victim->getLastDamageCause()->getDamager() instanceof Player){ $killer = $victim->getLastDamageCause()->getDamager()->getName(); $cmd = "rankpoints" . $killer . "5"; $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd); } } }
PlayerDeathEvent is called only when a player dies, so you are using the right event. Player->getLastDamageCause() will return the last EntityDamageEvent instance that Player took damage from. EntityDamageByEntityEvent inherits EntityDamageEvent and EntityDamageByChildEntityEvent inherits EntityDamageByEntityEvent. But EntityDamageByChildEntityEvent is called only when a projectile hits an entity and the shooter of the projectile is still online. To make it simple, you can check whether Player->getLastDamageCause() is an instance of EntityDamageByEntityEvent and the cause's getDamager() is a Player. PHP: public function onPlayerDeath(PlayerDeathEvent $event) : void{ $player = $event->getPlayer(); $cause = $player->getLastDamageCause(); if($cause instanceof EntityDamageByEntityEvent){ $damager = $cause->getDamager(); if($damager instanceof Player){ $killer = $damager->getName(); $cmd = "rankpoints {$killer} 5"; $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd); } }}