1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

FormAPI command not working

Discussion in 'Plugin Help' started by CupidonSauce173, Sep 22, 2018.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    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
     
  2. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    break statement is unreachable if you do "return true". remove them.
     
    Primus likes this.
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I tried and it doesnt work.
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    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');
                
    });
     
    Aericio likes this.
  5. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Still not working
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
    Is there any errors or unexpected behavior? Please elaborate for further assistance!
     
  7. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    There is no error, the form work and there is no other files...
     
  8. Primus

    Primus Zombie Pigman

    Messages:
    749
    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?
     
  9. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Exact
     
  10. Primus

    Primus Zombie Pigman

    Messages:
    749
    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;
                    }
     
  11. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    wait, echo and PHP_EOL works on pmmp ????
     
  12. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    nothing happen
     
  13. Primus

    Primus Zombie Pigman

    Messages:
    749
    Yes. Why wouldn't it?

    Post the console output.
     
  14. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    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)
     
  15. Primus

    Primus Zombie Pigman

    Messages:
    749
    Then you didn't add the echo. Because otherwise you should see the message(s). Show the code and console log, please?
     
    InspectorGadget likes this.
  16. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    PHP:
    2018-09-22 [20:43:17] [Server thread/INFO]: Disabling VanillaEntityAI v0.0.1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling AlwaysSpawn v2.2.4
    2018
    -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.1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling LinkPlayerCount v1.0.1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling BlockSniper v3.1.0
    2018
    -09-22 [20:43:17] [Server thread/INFO]: [BlockSniper] [BlockSniperLanguage selecteden
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling Farms v1.2-alpha
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling LobbyCore v1.0.0
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling BlocksConverter v1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling FormAPI v1.2.0
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling PearlCooldown v1.0.0
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling MultiWorld v1.4.3
    2018
    -09-22 [20:43:17] [Server thread/INFO]: [MultiWorldEnabling MultiWorld...
    2018-09-22 [20:43:17] [Server thread/INFO]: Enabling RealTime v1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling PurePerms v1.4.2
    2018
    -09-22 [20:43:17] [Server thread/NOTICE]: [PurePermsSet data provider to MySQL.
    2018-09-22 [20:43:17] [Server thread/INFO]: Enabling PortalsPE v1.1.1
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling Slapper v1.4.0
    2018
    -09-22 [20:43:17] [Server thread/INFO]: Enabling EconomyAPI v5.7.2
    2018
    -09-22 [20:43:18] [Server thread/NOTICE]: [EconomyAPI]
    2018-09-22 [20:43:18] [Server thread/NOTICE]: [EconomyAPIDatabase provider was set toYaml
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Enabling GuiShop v1.0.0-ALPHA1
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Enabling essentialsTP v1.2.1
    2018
    -09-22 [20:43:18] [Server thread/INFO]: [essentialsTPessentialsTPloading...
    2018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] [INFOloading [config.yml]....
    2018-09-22 [20:43:18] [Server thread/INFO]: [essentialsTP] [INFOloading [config.ymlDONE
    2018
    -09-22 [20:43:18] [Server thread/INFO]: [essentialsTPessentialsTPloaded!
    2018-09-22 [20:43:18] [Server thread/INFO]: Enabling Fireworks v0.0.1
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Enabling BlockEffects v1.0.0
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Enabling Neon v1.1.1
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Enabling PureChat v1.4.11
    2018
    -09-22 [20:43:18] [Server thread/NOTICE]: [PureChatFactionsPro 1.4 support enabled.
    2018-09-22 [20:43:18] [Server thread/INFO]: Enabling FactionsPro v1.3.12
    2018
    -09-22 [20:43:18] [Server thread/INFO]: [FactionsProAdd AntiSpamPro to ban rude Faction names
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Starting GS4 status listener
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Setting query port to 19133
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Query running on 0.0.0.0:19133
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Default game typeSurvival Mode
    2018
    -09-22 [20:43:18] [Server thread/INFO]: Done (1.155s)! For helptype "help" or "?"
    2018-09-22 [20:43:21] [Server thread/INFO]: CupidonSauce173[] logged in with entity id 1 at (world25666256)
    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);

            }
     
  17. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    As I said, there is nothing in console ...
     
  18. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    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 ?
     
  19. Primus

    Primus Zombie Pigman

    Messages:
    749
    If you find that suspicious then yes. That's the meaning of debugging without xdebug
     
    CupidonSauce173 likes this.
  20. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Ok well nothing appear
     
  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.