Not executing the command

Discussion in 'Development' started by DocTor, Jan 4, 2019.

  1. DocTor

    DocTor Creeper

    Messages:
    5
    GitHub:
    donthaveone
    So basically, i want my players to kick island members using the ui, everything works fine. But when I click the button to kick the X player, nothing happens. No errors too!



    ```public function FireUI($player){
    $api = Server::getInstance()->getPluginManager()->getPlugin("FormAPI");
    $form = $api->createSimpleForm(function (Player $event, $data){
    $player = $event->getPlayer();
    $result = $data[0];
    if($result != null){
    Server::getInstance()->getCommandMap()->dispatch($sender, "isle fire " . $result);
    }
    });
    $sb = Server::getInstance()->getPluginManager()->getPlugin("SkyBlock");
    $session = $sb->getSessionManager()->getSession($player);
    $form->setTitle("KIck Member");
    $form->setContent("Kick island member");
    $isle = $session->getIsle();
    $members = $isle->getMembers();
    foreach($members as $member){
    $name = $member->getUsername();
    $rank = $member->getRank();
    $form->addbutton($name);
    }
    $form->sendToPlayer($player);
    }
    }```

    help would be appreciated !
     
  2. DocTor

    DocTor Creeper

    Messages:
    5
    GitHub:
    donthaveone
    also Im new to pmmp forums so idrk how to minimize the code yk
     
  3. Diduhless

    Diduhless Slime

    Messages:
    96
    GitHub:
    Diduhless
    PHP:
    /** @var Server */
    private $server;

    /** @var string[] */
    private $players = [];

    /**
    * @param Player $player
    */
    public function sendKickForm(Player $player): void {
        
    $session SkyBlock::getInstance()->getSessionManager()->getSession($player);
        if(
    $session->hasIsle()) {
            
    /** @var FormAPI $instance */
            
    $instance $this->server->getPluginManager()->getPlugin("FormAPI");
            
    $form $instance->createSimpleForm(function (Player $player, ?int $result) {
                if(
    $result != null) {
                    
    $this->server->dispatchCommand($player"isle fire " $this->players[$result]);
                }
            });
            
    $form->setTitle("Kick Member");
            
    $form->setContent("Kick an island member");
            foreach(
    $session->getIsle()->getMembersOnline() as $member) {
                if(!isset(
    $this->players[array_search($username $member->getUsername(), $this->players)])) {
                    
    $this->players[] = $username;
                    
    $form->addButton($username);
                }
            }
            
    $player->sendForm($form);
        }
    }
    Your code is wrong, the second parameter of the api function returns an int while you're putting an array
    Also your command would be executed like this: /isle fire (number)
    Use mine and also try to understand it as it is very simple.
    Player names are stored in an array because you want to get them later.
     
  4. DocTor

    DocTor Creeper

    Messages:
    5
    GitHub:
    donthaveone
    Thanks for helping but still cant, first it show me a error about getPluginManager not found something like that, as the file is not the pluginbase i changed $this->server to Server::getInstance which fixed it. Then when I invite my alt to my island, he accepts it then I pressed a button (ingame) to take me to sendKickForm, it said could not find required property "buttons".
     
    Last edited: Jan 4, 2019
  5. Diduhless

    Diduhless Slime

    Messages:
    96
    GitHub:
    Diduhless
    Have you put FormAPI in the plugin folder? Also it has to be named 'FormAPI' as it says in the code
     
  6. DocTor

    DocTor Creeper

    Messages:
    5
    GitHub:
    donthaveone
    yes, forms works correctly its only when I press the form button which redirects me to sendKickForm
     
  7. Diduhless

    Diduhless Slime

    Messages:
    96
    GitHub:
    Diduhless
    Can you take a picture of the error?
     
  8. DocTor

    DocTor Creeper

    Messages:
    5
    GitHub:
    donthaveone
    Thank you for the help, but I fixed it! :D
     
  9. Diduhless

    Diduhless Slime

    Messages:
    96
    GitHub:
    Diduhless
    May you tell us how you've fixed it?
     

Share This Page

  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.