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

event problem

Discussion in 'Development' started by hexmor, Mar 25, 2020.

  1. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    hi . im trying to write a new plugin . im using EntityInventoryChangeEvent . i want to remove item on this event but i will get this error from console
    [14:39:44] [Server thread/CRITICAL]: RuntimeException: "Recursive event call detected (reached max depth of 50 calls)" (EXCEPTION) in "src/pocketmine/event/Event" at line 83
    the code

    $sender->getInventory()->removeItem(Item::get(2, 0, 1));
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I think this error appears when the even is in a loop.

    So it do something like this:
    PHP:
    onEvent();

    function 
    doEvent() {
       
    onEvent();
    }
     
  3. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    Explane more please . Should i do removing in other function ?
     
  4. Gianluxx

    Gianluxx Slime

    Messages:
    94
    GitHub:
    Gianluxx
    send all the function
     
  5. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    PHP:
    public function onInventoryTransactionEvent(EntityInventoryChangeEvent $event)  {
                
    $sender $event->getEntity();
                            if(
    $sender instanceof Player){
                                
    $source $event->getOldItem();
                                
    $target $event->getNewItem();
                                        if(
    $source->getNamedTag()->hasTag("Enchant")){
                                            
    $level $source->getNamedTag()->getInt("Level");
                                            
    $this->removeItemFrom($sender,$source);
                                            
    $enchant CustomEnchantManager::getEnchantmentByName($enchantName);
                                                    if (
    $enchant == null) {
                            
    Utils::errorForm($senderT::RED "Invalid enchantment.");
                            return;
                        }
                                            
    $item $target;
                                                        if (!
    $sender->hasPermission("piggycustomenchants.overridecheck")) {
                                                            if (!
    Utils::itemMatchesItemType($item$enchant->getItemType())) {
                                                                
                                                                    
    $sender->sendMessage(T::RED T::RED "The item is not compatible with this enchant.");
                                                        return;
                                                    }
                                                    
                                                    if (
    $level $enchant->getMaxLevel()) {
                                                        
                                                        
    $sender->sendMessage(T::RED T::RED "The max level is " $enchant->getMaxLevel() . ".");
                                                        
                                                        return;
                                                    }
                                                    
                                                    if (
    $item->getCount() > 1) {
                                                        
    $sender->sendMessage(T::RED T::RED "You can only enchant one item at a time.");
                                                    return;
                                                    }
                                                    
                                                        if (!
    Utils::checkEnchantIncompatibilities($item$enchant)) {
                                                            
    $sender->sendMessage(T::RED T::RED "This enchant is not compatible with another enchant.");
                                                        return;
                }
            }
                
            
            
    $item->addEnchantment(new EnchantmentInstance($enchant$level));
            
              
            
    $source->setLore([T::YELLOW."\nYou Can't Use This Anymore"]);
            
    $event->setNewItem($item);
                                        
                                        }
                            }
         }
    now i use a function to remove item but i get error agian . i just need to remove $source item
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You cannot manage the items in player's inventory in function which handles that.

    Player change item
    -> event will handle it
    -> you change item in player's inventory
    -> event will handle it
    -> ...

    That's loop
     
    HimbeersaftLP likes this.
  7. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    what should i do to delete the source item ?
     
  8. Gianluxx

    Gianluxx Slime

    Messages:
    94
    GitHub:
    Gianluxx
    use better checks (if)
     
  9. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    give me code please
     
  10. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I don't know... Your code doesn't make sense for me.. What's the purpose of the code?
     
  11. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Try to add some tag to save if the item is already checked... Then check just the items without this tag
     
  12. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    Im trying to make this plugin .

    I just dont know how to remove book ($source)
     
  13. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Add the enchnat directly
     
  14. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    code please
     
  15. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Give me the code where you handle the form
     
  16. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    piggy ce
     
  17. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    That doesn't seem as valid code... If you aren't satisfied with that plugin, ask plugin's author for fix that...
     
  18. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    im the author . its working . did you watch the video ?
     
  19. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
  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.