Help whit ShopUI with FormAPI

Discussion in 'Development' started by DrakerZR, May 16, 2018.

  1. DrakerZR

    DrakerZR Spider

    Messages:
    11
    Hi! Well, I'm doing a ShopUI with FormAPI, but I want if I touch a button, it gives me some items if i have money.
    I tried this:
    PHP:
    public function diamondarmorForm($player){
            if(
    $player instanceof Player){
                
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                
    $form $api->createSimpleForm(function (Player $event, array $data){
                    
    $player $event->getPlayer();
                    
    $cost 80000;
                    if(isset(
    $data[0])){
                        switch(
    $data[0]){
                            case 
    0:
                            if(
    EconomyAPI::getInstance()->myMoney($player) > $cost){
                                
    $player->getInventory()->addItem(Item::get(31001));
                                
    $player->getInventory()->addItem(Item::get(31101));
                                
    $player->getInventory()->addItem(Item::get(31201));
                                
    $player->getInventory()->addItem(Item::get(31301));
                                
    EconomyAPI::getInstance()->reduceMoney($player$cost);
                                
    $player->getLevel()->addSound(new EndermanTeleportSound($player), [$player]);
                                
    $player->sendMessage(C::BLACK "(>) " C::WHITE "You bought " C::GOLD "a complete Diamond Armor " C::WHITE "for " C::YELLOW "$" $cost);
                                }else{
                                    
    $player->getLevel()->addSound(new AnvilFallSound($player), [$player]);
                                    
    $player->sendMessage(C::RED "You have not enough money. Cost: $" $cost);
                                }
                            }
                            break;
                            case 
    1//That's line 1152
                            
    $this->menuForm($player);
                            break;
                        }
                    }
                });
                
    $form->setTitle("Confirm");
                
    $form->setContent(C::GREEN "Content:\n" C::AQUA "x1 Diamond Helmet\nx1 Diamond Chestplate\nx1 Diamond Leggings\nx1 Diamond Boots");
                
    $form->addButton("Buy");
                
    $form->addButton("Back");
                
    $form->sendToPlayer($player);
            }
        }
    Code Console:
    Code:
    2018-05-16 [01:59:57] [Server thread/INFO]: Loading ShopUI v1.0dev
    2018-05-16 [01:59:57] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'case' (T_CASE)" (EXCEPTION) in "ShopUI.phar/src/ShopUI/Main" at line 1152
    What did I do Wrong?
     
  2. LewBr

    LewBr Zombie

    Messages:
    382
    GitHub:
    lewbr
    You set the curly braces wrong at the line 1150 i think, fixed for you:
    PHP:
                            switch($data[0]){
                            case 
    0:
                            if(
    EconomyAPI::getInstance()->myMoney($player) > $cost){
                                
    $player->getInventory()->addItem(Item::get(31001));
                                
    $player->getInventory()->addItem(Item::get(31101));
                                
    $player->getInventory()->addItem(Item::get(31201));
                                
    $player->getInventory()->addItem(Item::get(31301));
                                
    EconomyAPI::getInstance()->reduceMoney($player$cost);
                                
    $player->getLevel()->addSound(new EndermanTeleportSound($player), [$player]);
                                
    $player->sendMessage(C::BLACK "(>) " C::WHITE "You bought " C::GOLD "a complete Diamond Armor " C::WHITE "for " C::YELLOW "$" $cost);
                                }else{
                                    
    $player->getLevel()->addSound(new AnvilFallSound($player), [$player]);
                                    
    $player->sendMessage(C::RED "You have not enough money. Cost: $" $cost);
                                }
                            break;
                            case 
    1//That's line 1152
                            
    $this->menuForm($player);
                            break;
                            }
     
    DrakerZR likes this.
  3. DrakerZR

    DrakerZR Spider

    Messages:
    11
    It Worked! Thanks
     

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.