1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved PlayerItemHeldEvent bug?

Discussion in 'Development' started by minijaham, Oct 2, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Hello! I came across making this "setting lore on the item when held" code and I encountered some bugs.
    PHP:
    public function itemHeld(PlayerItemHeldEvent $event) {
        
    $item $event->getItem();
        
    $player $event->getPlayer();
        foreach (
    $item->getEnchantments() as $enchantmentInstance) {
            
    $enchantment $enchantmentInstance->getType();
            if (
    $item->getId() === 403 && $enchantment instanceof CustomEnchant) {
                    
    $enchant CustomEnchantManager::getEnchantmentByName($enchantment->getDisplayName());
                    
    $lore = [
                            
    " ",
                            
    TextFormat::RESET TextFormat::YELLOW $enchant->getDescription(),
                            
    " ",
                            
    TextFormat::RESET TextFormat::GRAY "You need 20 levels to combine!",
                            
    TextFormat::RESET TextFormat::GRAY "Drag'n drop to the item to enchant"
                            
    ];
                            if (
    $item->getLore() === $lore){
                            } else {
                                
    $item->setLore($lore);
                                
    $player->getInventory()->setItemInHand($item);
                            }
                        }
                    }
                }
            }
    The code works perfectly fine on giving the item(setItemInHand), but it doesn't seem to remove the old item.

    I've also tried removeItem($player->getInventory()->getItemInHand) but didn't work either
     
  2. Besher

    Besher Witch

    Messages:
    51
    try putting air in player inventory slot!
     
    minijaham likes this.
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Thank you for your answer! However, I forgot to put the prefix as solved..
    I've fixed the issue a while ago. But thank you again for your reply!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.