hi, so I try to make a form to work and I have no clue on what I do wrong....here is the code PHP: public function onInteract(PlayerInteractEvent $event) { $player = $event->getPlayer(); $item = $player->getInventory()->getItemInHand(); if ($item->getCustomName() == TextFormat::RED . "Servers List") { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $navform = $api->createSimpleForm(function (Player $player, array $data) { $navresult = $data[0]; if ($result === null) { return true; } switch ($result) { case 0: $player->transfer("an ip", "19132"); return true; break; case 1: $player->transfer("an ip", "19133"); return true; break; } }); $navform->setTitle("§l§aServer Selector"); $navform->setContent(" Select The Server You Want To Play!"); $navform->addButton(TextFormat::BOLD . "PvP §7- §7[§aserver§7]"); $navform->addButton(TextFormat::BOLD . "§aFactions §7- §7[§aserver§7]"); $navform->sendToPlayer($player); } help please
Did your code get through this ? PHP: if ($item->getCustomName() == TextFormat::RED . "Servers List") { What the heck is $result in the scope of Closure? You've never defined it in that context. Also no array is passed to Closure when using simple form. Use this instead PHP: $navform = $api->createSimpleForm(function (Player $player, ? int $result = null) { if ($result === null) { return true; } switch ($result) { case 0: $player->transfer("an ip", "19132"); break; case 1: $player->transfer("an ip", "19133"); break; } // I would use array for something like this // if(isset(servers[result])) player->transfer(servers[result][0], servers[result][1]); // else player->sendMessage('Server unavailable'); });
File management is not even involved in this. If the form works, which part doesn't? It doesn't do anything when you click the button or something?
Alright, you should do some debugging. Let's find out what value is passed as $result to form handling function. Try this and post the console output. PHP: $navform = $api->createSimpleForm(function (Player $player, ? int $result = null) { echo "Result: ". ($result === null ? "null" : $result) . PHP_EOL; if ($result === null) { echo "Result was null, so handling was stopped." . PHP_EOL; return true; }
There is nothing about the plugin in console (I mean, the forms keep working but there is no messages in console when trying a button)
Then you didn't add the echo. Because otherwise you should see the message(s). Show the code and console log, please?
PHP: 2018-09-22 [20:43:17] [Server thread/INFO]: Disabling VanillaEntityAI v0.0.12018-09-22 [20:43:17] [Server thread/INFO]: Enabling AlwaysSpawn v2.2.42018-09-22 [20:43:17] [Server thread/INFO]: AlwaysSpawn Enabled!2018-09-22 [20:43:17] [Server thread/INFO]: Preparing level "world"2018-09-22 [20:43:17] [Server thread/INFO]: Enabling SignServerStats v1.1.12018-09-22 [20:43:17] [Server thread/INFO]: Enabling LinkPlayerCount v1.0.12018-09-22 [20:43:17] [Server thread/INFO]: Enabling BlockSniper v3.1.02018-09-22 [20:43:17] [Server thread/INFO]: [BlockSniper] [BlockSniper] Language selected: en2018-09-22 [20:43:17] [Server thread/INFO]: Enabling Farms v1.2-alpha2018-09-22 [20:43:17] [Server thread/INFO]: Enabling LobbyCore v1.0.02018-09-22 [20:43:17] [Server thread/INFO]: Enabling BlocksConverter v12018-09-22 [20:43:17] [Server thread/INFO]: Enabling FormAPI v1.2.02018-09-22 [20:43:17] [Server thread/INFO]: Enabling PearlCooldown v1.0.02018-09-22 [20:43:17] [Server thread/INFO]: Enabling MultiWorld v1.4.32018-09-22 [20:43:17] [Server thread/INFO]: [MultiWorld] Enabling MultiWorld...2018-09-22 [20:43:17] [Server thread/INFO]: Enabling RealTime v12018-09-22 [20:43:17] [Server thread/INFO]: Enabling PurePerms v1.4.22018-09-22 [20:43:17] [Server thread/NOTICE]: [PurePerms] Set data provider to MySQL.2018-09-22 [20:43:17] [Server thread/INFO]: Enabling PortalsPE v1.1.12018-09-22 [20:43:17] [Server thread/INFO]: Enabling Slapper v1.4.02018-09-22 [20:43:17] [Server thread/INFO]: Enabling EconomyAPI v5.7.22018-09-22 [20:43:18] [Server thread/NOTICE]: [EconomyAPI]2018-09-22 [20:43:18] [Server thread/NOTICE]: [EconomyAPI] Database provider was set to: Yaml2018-09-22 [20:43:18] [Server thread/INFO]: Enabling GuiShop v1.0.0-ALPHA12018-09-22 [20:43:18] [Server thread/INFO]: Enabling essentialsTP v1.2.12018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] essentialsTP+ loading...2018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] [INFO] loading [config.yml]....2018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] [INFO] loading [config.yml] DONE2018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] essentialsTP+ loaded!2018-09-22 [20:43:18] [Server thread/INFO]: Enabling Fireworks v0.0.12018-09-22 [20:43:18] [Server thread/INFO]: Enabling BlockEffects v1.0.02018-09-22 [20:43:18] [Server thread/INFO]: Enabling Neon v1.1.12018-09-22 [20:43:18] [Server thread/INFO]: Enabling PureChat v1.4.112018-09-22 [20:43:18] [Server thread/NOTICE]: [PureChat] FactionsPro < 1.4 support enabled.2018-09-22 [20:43:18] [Server thread/INFO]: Enabling FactionsPro v1.3.122018-09-22 [20:43:18] [Server thread/INFO]: [FactionsPro] Add AntiSpamPro to ban rude Faction names2018-09-22 [20:43:18] [Server thread/INFO]: Starting GS4 status listener2018-09-22 [20:43:18] [Server thread/INFO]: Setting query port to 191332018-09-22 [20:43:18] [Server thread/INFO]: Query running on 0.0.0.0:191332018-09-22 [20:43:18] [Server thread/INFO]: Default game type: Survival Mode2018-09-22 [20:43:18] [Server thread/INFO]: Done (1.155s)! For help, type "help" or "?"2018-09-22 [20:43:21] [Server thread/INFO]: CupidonSauce173[] logged in with entity id 1 at (world, 256, 66, 256)2018-09-22 [20:43:21] [Server thread/INFO]: CupidonSauce173 joined the game PHP: public function onInteract(PlayerInteractEvent $event) { $player = $event->getPlayer(); $item = $player->getInventory()->getItemInHand(); if ($item->getCustomName() == TextFormat::YELLOW . "Navigator") { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $navform = $api->createSimpleForm(function (Player $player, ? int $result = null) { echo "Result: ". ($result === null ? "null" : $result) . PHP_EOL; if($result === null){ echo "Result was null, so handling was stopped." . PHP_EOL; return true; } }); $navform->setTitle("§l§aServer Selector"); $navform->setContent(" Select The Server You Want To Play!"); $navform->addButton(TextFormat::BOLD . "PvP §7- §7[§cVERSAI§7]"); $navform->addButton(TextFormat::BOLD . "§aFactions §7- §7[§cCryoServers§7]"); $navform->sendToPlayer($player); }
But it doesn't work for sure. You tell the plugin to send a message in console if there is no result..But I do click on a button so there is a result, shouldn't be more in case 1: that I should put the echo ?