I made a plugin that use the command /steak and a slider will come up where they can choose how many steak they want to get(min:0 max:64) but how do i get the results ? im using formapi PHP: $plugin = $this->getServer()->getPluginManager(); $formapi = $plugin->getPlugin("FormAPI"); $form = $formapi->createCustomForm(function (Player $p, array $args){ $steak = $args[0]; if($steak == "0"){ $p->getInventory()->addItem(Item::get(264, 0, 1)); // i can do it till 64 but it'll be hard and will take long, any shortcuts? } }); $form->setTitle(); $form->addSlider(); $form->sendToPlayer($p);
Just change $sender to $p PHP: $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if($api === null || $api->isDisabled()){ // CHECK THIS ? } $form = $api->createCustomForm(function (Player $sender, array $data){ $result = $data[0]; if($result != null){ $sender->getInventory()->addItem(Item::get(264, 0, $result)); } }); $form->setTitle(TextFormat::BOLD . TextFormat::BLUE . "Want to order Diamond"); $form->addSlider("Amount" , 1, 64, 1); $form->sendToPlayer($sender);
Use DataPacketReceiveEvent & ModalFormResponsePacket. do not forget that the client is sending data to json. you can use PHP: json_decode($formData, true);