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));
I think this error appears when the even is in a loop. So it do something like this: PHP: onEvent();function doEvent() { onEvent();}
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($sender, T::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
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
Try to add some tag to save if the item is already checked... Then check just the items without this tag
That doesn't seem as valid code... If you aren't satisfied with that plugin, ask plugin's author for fix that...
let me send you full plugin . https://www.mediafire.com/file/s8rwz85ranyae8u/BookEnchantShop.rar/file