Hello, from some updates of the PocketMine API the Plugins that I have done that require FormAPI do not do their job, like this: PHP: public function openTestForm($player){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, int $data = null){ $result = $data; if($result === null){ return true; } switch($result){ case "0"; $player->sendMessage("The Form is working correctly"); break; } }); $form->setTitle("Test"); $form->setContent(T::GREEN."Press the button"); $form->addButton("1"); $form->sendToPlayer($player); return $form; } And when will I have clicked on the "1" button, absolutely nothing happens, nor does it give any errors in the console, please help me, tell me what happens.
Yes, I changed the result to int but nothing happened, still does not send the message to the player: PHP: public function openTestForm($player){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, int $data = null){ $result = $data; if($result === int){ return true; } switch($result){ case "0"; $player->sendMessage("The Form is working correctly"); break; } }); $form->setTitle("Test"); $form->setContent(T::GREEN."Press the button"); $form->addButton("1"); $form->sendToPlayer($player); return $form; }
No, don't do that. Do you want to see the result of that being used? Code: [19:49:45] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.2.0': Use of undefined constant int - assumed 'int' (this will throw an Error in a future version of PHP) on jojoe77777\FormAPI\FormAPI [19:49:45] [Server thread/CRITICAL]: ErrorException: "Use of undefined constant int - assumed 'int' (this will throw an Error in a future version of PHP)" (EXCEPTION) in "TestProject/src/Aericio/TestProject/Commands/TestCommand" at line 67 I've just tested your original code and it works fine. Ensure that you are: - calling it properly - chat is not muted - FormAPI is installed Additionally, add some beautiful checks
I think this code working, try this Code: public function openTestForm($player){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, array $data){ $result = $data[0]; if($result === int){ return true; } switch($result){ case 0: $player->sendMessage("The Form is working correctly"); break; } }); $form->setTitle("Test"); $form->setContent(T::GREEN."Press the button"); $form->addButton("1"); $form->sendToPlayer($player); }
What exactly are you trying to accomplish with this form? Again, revert the "if($result === int){}" back to "if($result === null){}"
This code working PHP: public function openTestForm($player){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, int $data = null){ $result = $data; if($result === null){ return; } switch($result){ case 0; $player->sendMessage("The Form is working correctly"); return; break; } }); $form->setTitle("Test"); $form->setContent("Press the button"); $form->addButton("1"); $form->sendToPlayer($player); return $form; }
No, the original code does not work, the form is opened but at the moment of pressing the button nothing happens. (Working in API 3.2.0)