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

can smbdy help me?

Discussion in 'Plugin Help' started by zenqibruh, May 16, 2022.

  1. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    PHP:
    public function queue(Player $player)
        {
            if (empty(
    $this->alr[$player->getUniqueId()->toString()])) {
                
    $this->queue[] = $player->getName();
                
    $this->alr[$player->getUniqueId()->toString()] = true;
            }
        }

    PHP:
    public function onInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            
    $inst ItemFactory::getInstance();
            
    $it VanillaItems::DIAMOND();
            
    $form = new SimpleForm(function (Player $playerint $data null){
                
    $result $data;
                if(
    $result === null){ // Closed form without submitting
                    
    return;
                }
                switch(
    $result){
                    case 
    0:
                        
    $this->queue($player);
                        if (
    count($this->queue) == 2) {
                            
    $arr array_shift($this->queue);
                            
    $player1 $this->getServer()->getPlayerExact($this->queue[0]);
                            
    $player2 $this->getServer()->getPlayerExact($this->queue[1]);
                            if (
    $player1 instanceof Player || $player2 instanceof Player) {
                                
    $player2->sendMessage("lmao");
                                
    $player1->sendMessage("zzz");
                            }
                        }
                        
    print_r(count($this->queue));
                        
    $player->sendMessage("a");
                        
    print_r($this->queue);
                        break;
                }
            });

            
    $form->addButton("Duels");
            
    $form->setTitle("Play");
            if (
    $event->getItem() == $it) {
                
    $this->getLogger()->info("worked!");
                
    $form->sendToPlayer($player);
            }
        }

    undefined array key 1 on line 54 ( $player2 = $this->getServer()->getPlayerExact($this->queue[1]); )
     
  2. cosmicnebula

    cosmicnebula Spider

    Messages:
    8
    GitHub:
    cosmicnebula200
    because you have used `array_shift` the array no longer has 2 keys in it.
     
  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.