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

FormAPI not working

Discussion in 'Development' started by BlawoHD, Sep 2, 2018.

  1. BlawoHD

    BlawoHD Silverfish

    Messages:
    21
    Command is not working for FormAPI?

    PHP:
    <?php


    namespace BlawoHD;


    use 
    pocketmine\Server;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\TextFormat;

    use 
    pocketmine\Player;

    use 
    pocketmine\command\Command;

    use 
    pocketmine\command\CommandSender;

    use 
    pocketmine\command\CommandExecutor;

    use 
    pocketmine\command\ConsoleCommandSender;


    class 
    Main extends PluginBase implements Listener {

       

            public function 
    onEnable() {

            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");

            if(
    $api === null){

                
    $this->getServer()->getPluginManager()->disablePlugin($this);           

            }

            }

       

          public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {

            if(
    $cmd->getName() == "dsgvo"){

                if(
    $sender instanceof Player) {

                    
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");

                    
    $form $api->createModalForm(function (Player $sender, array $data){

                        
    $result $data[0];

                       

                        if(
    $result === null){

                            return 
    true;

                        }

                        switch(
    $result){

                               

                        }

                    });

                    
    $form->setTitle("DSGVO");

                    
    $form->setContent("Bitte Akzeptiere die Datenschutzrichtlinie des Server!");

                    
    $form->setButton1(TextFormat::GREEN "Akzeptieren");

                    
    $form->setButton2(TextFormat::DARK_RED "Ablehnen");

                    
    $form->sendToPlayer($sender);

                }

                break;

            }

            return 
    true;

        }

    }
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    it must be ? bool data
    PHP:

                    $form 
    $api->createModalForm(function (Player $sender, ? bool $resultnull){
                        if(
    $result === null){
                            return 
    true;
                        }

                       if(
    $result) {

                       } else {

                       }

                    });
    Reffer to: https://github.com/BlockHorizons/FactionsPE/blob/reborn/src/factions/command/LeaveFaction.php#L53
     
  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.