Is there any possible way to get the name of an item on EntityEatEvent? I see getFoodSource, but no relations that are as close.
I have this, but it'll do it for all golden apples. Maybe make a new meta for the golden apple? PHP: public function onEat(Eat $event){ $players = $this->getServer()->getOnlinePlayers(); foreach($players as $player){ $p = $event->getEntity(); $head = Item::get(Item::GOLDEN_APPLE); $head->setCustomName(TF::GOLD.'Golden Head'); if($p instanceof Player){ if($head === $event->getFoodSource()) { $p->addEffect(Effect::getEffectByName(Effect::ABSORPTION)->setAmplifier(2)->setDuration(20 * 60 * 3)); $p->addEffect(Effect::getEffectByName(Effect::REGENERATION)->setAmplifier(2)->setDuration(20 * 9)); $p->addEffect(Effect::getEffectByName(Effect::DAMAGE_RESISTANCE)->setAmplifier(1)->setDuration(20 * 15)); } } } }
Ok, I did figure it out. You can use PlayerItemConsumeEvent, which in turn you are able to get the item and therefore get the name.