Im actually trying to get the player who killed as well as the player who dies..not sure how to get the victim PHP: public function onPlayerDeath(PlayerDeathEvent $event){ $player = $event->getEntity(); $cause = $event->getEntity()->getLastDamageCause()->getCause(); $entity = $event->getEntity(); $cause = $entity->getLastDamageCause(); if($cause instanceof EntityDamageByEntityEvent) { $killer = $cause->getDamager()->getPlayer() $victim = $player->getEntity........... :(
PHP: $victim = $event->getPlayer(); Also, when you call $cause->getDamager(), you don't need to call Player::getPlayer() because it already returns at entity. You do, however, have to make sure the entity is a player.
Here an example how you can handle player deaths PHP: public function onPlayerDeath(PlayerDeathEvent $event){ $entity = $event->getEntity(); $killer = $entity->getLastDamageCause(); if($killer instanceof EntityDamageByEntityEvent) { $killer = $killer->getDamager(); if($killer instanceof Player) { //The reason for the death on our Player was an other Player ($killer) } else { //The reason for the death on our Player ($entity) was NOT an Player but it was an Entity } } else { //The reason for the death on our Player ($entity) was NOT an Player/Entity }}
ok, doesn't the "//The reason for the death on our Player ($entity) was NOT an Player/Entity" not do anything? i always thought the // was just to add notes or somthing.
Instead of making a new thread..ill just ask here lol i got what i was doing with the killer and victim working fine now im wondering if i can use things from economy api in a different plugin? What i am working on is taking killcash or killmoney and modding it a bit..dont hate me im not planning on taking credit or trying to post it, i like the plugin but im making it take the money from the victim now i just need to figure out how to cancel the event if the victim has no money.. PHP: public function onPlayerDeath(PlayerDeathEvent $event){ if($this->economy == true && $this->config->get("enable") == "true"){ $entity = $event->getEntity(); $killer = $entity->getLastDamageCause(); if($killer instanceof EntityDamageByEntityEvent){ } $killer = $killer->getDamager(); if($killer instanceof Player) if($this->config->get("economy-plugin") == "EconomyAPI") { $msg = str_replace("{money}", $this->config->get("money"), $this->config->get("message")); $killer->sendMessage("$msg"); $entity->sendMessage("$Vmessage"); $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->reduceMoney($entity->getName(), $this->config->get("money")); $event->$this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney($killer->getName(), $this->config->get("money")); return true; } $money = $this->config->get("money"); if(EconomyAPI::getInstance()->reduceMoney($entity, $money, true, "EconomyATP") === EconomyAPI::RET_INVALID){ $killer->sendMessage("Victim had no money to steal!")); return true;
maybe somthing like this? PHP: if($this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->getMoney($entity) === EconomyAPI::RET_INVALID)