There's a bug with both PlayerDeathEvent and EntityDeathEvent. When one entity kills another and I check if both are instanceof player, the code does not execute but without checking it does. Here's my code: PHP: /** * @param EntityDeathEvent|PlayerDeathEvent $event */ public function onDeath(EntityDeathEvent $event){ $target = $event->getEntity(); $cause = $event->getEntity()->getLastDamageCause(); if($cause instanceof EntityDamageEvent){ if($target instanceof Player){ $this->core->PocketLegionLevels()->setDeaths($target, $this->core->PocketLegionLevels()->getDeaths($target) + 1); } } if($cause instanceof EntityDamageByEntityEvent){ $killer = $cause->getDamager(); if($killer instanceof Player and $target instanceof Player){ $this->core->PocketLegionLevels()->setKills($killer, $this->core->PocketLegionLevels()->getKills($killer) + 1); $this->core->PocketLegionLevels()->setDeaths($target, $this->core->PocketLegionLevels()->getDeaths($target) + 1); if($this->core->PocketLegionLevels()->getCrate($killer)){ $level = $this->core->PocketLegionLevels()->getLevel($killer); Server::getInstance()->broadcastMessage(RandomUtils::colorMessage(str_replace(['@player', '@level'], [$killer->getName(), $level], $this->core->getMessage('levels', 'receive_crate')))); } if($this->core->PocketLegionLevels()->playerLevelUp($killer)){ $level = $this->core->PocketLegionLevels()->getLevel($killer); Server::getInstance()->broadcastMessage(RandomUtils::colorMessage(str_replace(['@player', '@level'], [$killer->getName(), $level], $this->core->getMessage('levels', 'level_up')))); } } return; } }
What else could they be besides Players? I already tested it by killing another Player and it isn't doing anything.
If everything you stated is true, then a check isn't passing somewhere. There is absolutely 0 harm in debugging every variable.
Ok, sure. I'll try it but I don't have another player to test it. Is there a way I can spawn a testing NPC?
does every time the event fires before your instance of player check echo '$killer class: '.getclassname($killer); echo '$target class: '.getclassname($target);