Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting item name of EntityEatEvent

Comments in 'Plugin Development' started by Irish, Apr 30, 2016.

  1. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Is there any possible way to get the name of an item on EntityEatEvent? I see getFoodSource, but no relations that are as close.
  2. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    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));
                }
                }
            }
        }
  3. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    There is probably a way to make this shorter, but I can do that later :D
  4. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    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. :D

Share This Page

Advertisement