Recursive event call detected

Discussion in 'Development' started by xXNiceAssassinlo YT, Mar 16, 2019.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    Hello, I am trying to fix my plugin but this error "RuntimeException: "Recursive event call detected (reached max depth of 50 calls)" (EXCEPTION) in "src/pocketmine/event/Event" at line 87" keep popping mind helping me fix it. I think it means there are too many blocks i dont know lol, also mind telling me what is $step in https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/level/Level.php#L1692

    Here is my try.
    PHP:
        public function onBreak(BlockBreakEvent $e): void{
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $inv $player->getInventory()->getItemInHand();

            if(
    $this->check($player)){
                
    $en $this->getEnchant($player);
                
    $s $block->getSide(Facing::SOUTH);
                
    $player->getLevel()->useBreakOn($s$inv$player);
            }
        }
    I am trying to break block like this
    xox
    xox
    xxx

    O is the broken blocks, I know I am suppose to use getDirection which comes later after I am done with this testing lol or Facing::ALL or smth I forgot.
     
    Last edited: Mar 16, 2019
  2. KielKing

    KielKing Zombie

    Messages:
    246
    GitHub:
    kielking
    Level->useBreakOn() calls BlockBreakEvent so your function keeps looping forever, you might want to set a threshold or find another way
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,877
    GitHub:
    sof3
    jasonwynn10 likes this.
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    Oh whoops I mean in getSide xd
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    I am trying to make a plugin, which mines 4 by 4 but I keep getting this error + I knew it was looping bc I checked with var dump but idk how to stop it
     
  6. jasonwynn10

    jasonwynn10 Wither Skeleton Poggit Reviewer

    Messages:
    1,371
    GitHub:
    jasonwynn10
     
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    jasonwynn10 likes this.
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,877
    GitHub:
    sof3
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    Oh nvm I got it lol sorry for asking
     
  10. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    Anyone help with the real question I asked, to fix that err
     
  11. TheClimbing

    TheClimbing Spider Jockey

    Messages:
    32
    GitHub:
    theclimbing
    Well since
    Code:
    useBreakOn()
    calls block break event you will have to use different event for example on command or on placing a specific block
     
  12. wolfdale

    wolfdale Zombie

    Messages:
    304
    You can use a task to do that, also you should check if the block is breakable, and set a limit if not it will go on forever
    PHP:
       public function onBreak(BlockBreakEvent $e): void{
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $inv $player->getInventory()->getItemInHand();

            if(
    $this->check($player)){
                
    $en $this->getEnchant($player);
                
    $s $block->getSide(Facing::SOUTH);
                if(
    $s->isBreakable($inv))//optionally you can set a limit
                
    $this->delayedBlockBreak($s$inv$player);
            }
        }
    function 
    delayedBlockBreak(Vector3 $block,Item $item null,Player $player null){
    $this->getScheduler()->scheduleDelayedTask(new class($block,$item,$player) extends Task{
    private 
    $block,$item,$player;
    function 
    __construct(Vector3 $block,Item $item null,Player $player null){
    $this->block $block;
    $this->item $item;
    $this->player $player;
    }
    function 
    onRun(int $currentTick){
    if(!
    $this->block->getLevel()->isClosed() && (!$this->player || $this->player->isOnline())
    $this->block->getLevel()->useBreakOn($this->block,$this->item,$this->player);
    }
    },
    1);
    }
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,877
    GitHub:
    sof3
    Protip: use ClosureTask to improve conciseness and reduce boilerplate code. It was added in API 3.4.0
     
    jasonwynn10 likes this.
  14. KielKing

    KielKing Zombie

    Messages:
    246
    GitHub:
    kielking
     

Share This Page

  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.