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

Solved Wait for event

Discussion in 'Development' started by Dyntes, Oct 23, 2020.

  1. Dyntes

    Dyntes Spider Jockey

    Messages:
    48
    GitHub:
    Dyntes
    Hi, is there anyone know how to make a code tht wait until an event is executed?
    My code↓

    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$lbl$args):bool{
        switch(
    $cmd->getName()){
            case 
    "test":{
                
    $sender->sendMessage("Please execute a block");
                
    //wait until the event below is executed
                
    break;
            }
        return 
    true;
    }

    public function 
    onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $block $event->getBlock();   //question: how to save this variables to the function above??
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Something like this would work
    PHP:
    private $wait = [];
    public function 
    onCommand(CommandSender $senderCommand $cmd$lbl$args):bool{
        switch(
    $cmd->getName()){
            case 
    "test":{
                
    $sender->sendMessage("Please execute a block");
                
    $this->wait[$sender->getId()] = true;
                
    //wait until the event below is executed
                
    break;
            }
        return 
    true;
    }

    public function 
    onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        if(isset(
    $this->wait[$player->getId()]){
            
    //do stuff
            
    unset($this->wait[$player->getId()]);
        }
    }
     
    Primus likes this.
  3. Dyntes

    Dyntes Spider Jockey

    Messages:
    48
    GitHub:
    Dyntes
    Ohh tq
     
  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.