Plz i need more informations Which type of Form? Where (Title, content, label...)? Wath do you want to do with that?
Custom Form type I making shop plugin. I added amount with slider. But I dont check player's money. Please example.
I tested $data[0] !== null. This method worked but I don't check player's money. After I tested switch case. It's not worked. Exampleee!
My code : PHP: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $eco = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); $parasi = $eco->myMoney($g); $f = $api->createCustomForm(function (Player $g, array $data){ $s = $data[0]; if($s == null) { return true; } switch($s) { case 0: if(!empty($parasi)) { if($parasi > 75*$s) { $g->getInventory()->addItem(Item::get(1,0,$s)); $g->sendMessage("You boght $s stone."); EconomyAPI::reduceMoney($g, 75*$s); }else{ $g->sendMessage("§cNot moneu."); } } break; } }); $f->setTitle("§lShop"); $f->addSlider("§7Amount",1,64); $f->sendToPlayer($g);
Also i suggest you to try that on PluginCommand its much better than the default one, i was trying FormAPI in onCommand() function and it didnt work but i tested it again with PluginCommand and it worked perfectly
Is the logic collapsed? Points to note: PHP: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $eco = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); // $parasi = $eco->myMoney($g); NOTE: Move for explanation to example() $f = $api->createCustomForm([$this, "example"]); $f->setTitle("§lShop"); $f->addSlider("§7Amount",1,64); $f->sendToPlayer($g); /** * Callback function. * The execution result of the form is assigned to the argument $data * If the form is closed rather than sent, NULL is assigned to $data * @param Player $g * @param array $data * @return void */ public function example(Player $g, array $data) { $s = $data[0];// slider`s value if($s == null) { return true;// cancelled } $parasi = $eco->myMoney($g); // Since the number of items is variable, you do not need to switch the process with switch switch($s) { case 0: // Since the value of the slider is set between 1 and 64, processing does not go to here // The value in $perasi is **float** or **bool** according to EconomyAPI. if ($parasi !== false) { if($parasi > 75*$s) { $g->getInventory()->addItem(Item::get(1,0,$s)); $g->sendMessage("You boght $s stone."); EconomyAPI::reduceMoney($g, 75*$s); }else{ $g->sendMessage("§cNot moneu."); } } break; } } Please rewrite like this: PHP: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $eco = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); $parasi = $eco->myMoney($g); $f = $api->createCustomForm(function (Player $g, array $data) { // NOTE: Callback function - START // If you do not check whether the form was interrupted for the first time, // $data may be null and it can not be acquired if($s == null) { return true;// cancelled } $s = $data[0];// slider`s value. The value from 1 to 64 should come back $parasi = $eco->myMoney($g); if ($parasi !== false) { if($parasi > 75*$s) { $g->getInventory()->addItem(Item::get(1,0,$s)); $g->sendMessage("You boght $s stone."); EconomyAPI::reduceMoney($g, 75*$s); }else{ $g->sendMessage("§cNot moneu."); } } }); // NOTE: Callback function - END $f->setTitle("§lShop"); $f->addSlider("§7Amount",1,64); $f->sendToPlayer($g);