PHP: public function onKill(EntityDamageEvent $event){ $player = $event->getEntity(); if($event instance EntityDamageByEntityEvent){ $damager = $event->getDamager(); if($event->getFinalDamage() >= $player->getHealth()){ $kitem = $damager->getItemInHand(); $kitem->setLore(["test", "test1"]); $damager->getInventory()->setItemInHand($kitem); } }} Why wont this work? addItem() works..
PHP: public function onDeath(PlayerDeathEvent $event){ $p = $event->getEntity(); $cause = $p->getLastDamageCause(); if ($cause instanceof EntityDamageByEntityEvent) { $killer = $cause->getDamager(); if ($killer instanceof Player) { $kitem = $killer->getItemInHand(); $kitem->setLore(["test", "test1"]); $killer->getInventory()->setItemInHand($kitem); $killer->getInventory()->sendContents($killer); } }} This didn't work either
It won't work. This is roughly how pocketmine handles updating item in hand currently... Code: $item = item in hand; callEvent -> EntityDamageEvent if(event is cancelled){ return; } Item->applyDamage(1); Player->getInventory()->setItemInHand(item); Any changes to item in hand will be overridden after the event has been handled by all event listeners. You'll need to somehow run the code after the event is called and handled, which surely can't be done during the event. So updating the item after a one tick delay seems to be the appropriate solution. Oh, and also... the player's item in hand may not be the same by the next tick, so you'll need to check if it's the same item. I suggest completely shifting the event handling into the task if you're merely monitoring the task. The player could also disconnect by the next tick, you can use an if(!$player->isConnected()) return;