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

Another little help with FormAPI

Discussion in 'Development' started by Khaled, Feb 13, 2018.

  1. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    I was trying to make a dropdown and select a player then i type a message in the input and the player i chose get the message.
    My attempt:
    PHP:
    <?php

    namespace ddui\Command;

    use 
    pocketmine\Player;
    use 
    jojoe77777\FormAPI;
    use 
    pocketmine\command\{
        
    Command,
        
    CommandSender
    };
    use 
    pocketmine\command\PluginCommand;
    use 
    ddui\DropdownUI;

    class 
    DropdownCMD extends PluginCommand {
       
        public function 
    __construct($commandDropdownUI $plugin){
            
    parent::__construct($command$plugin);
        }
       
        public function 
    execute(CommandSender $senderstring $commandLabel, array $args){
            
    $api $this->getPlugin()->getServer()->getPluginManager()->getPlugin("FormAPI");
            if(
    $api === null){
                return 
    true;
            }
            
    $form $api->createCustomForm(function(Player $sender, array $data){
                if(
    data[0] != null){
                    
    $cmd "tell ".$data[0]."  ".$data[1];
                    
    $this->getPlugin()->getServer()->getCommandMap()->dispatch($sender$cmd);
                    return 
    true;
                }
            });
            
    $form->setTitle("TestDropdown");
            
    $form->addDropdown("Dropdown"$this->getPlugin()->getServer()->getOnlinePlayers());
            
    $form->addInput("Message");
            
    $form->sendToPlayer($sender);
        }
    }
    ?>
    The Plugin Works Fine but the player doesnt get the message.
     
  2. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    And i got the error from the console:
    PHP:
    00:25:55 [ServerServer thread/CRITICAL Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.0.0': Use of undefined constant data assumed 'data' (this will throw an Error in a future version of PHPon jojoe77777\FormAPI\FormAPI 14.02 00:25:55 [ServerServer thread/CRITICAL ErrorException"Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP)" (EXCEPTIONin "DropdownUIEdited_v1.0.4.phar/src/ddui/Command/DropdownCMD" at line 26 14.02 00:25:55 [ServerServer thread/DEBUG #0 DropdownUIEdited_v1.0.4.phar/src/ddui/Command/DropdownCMD(26): pocketmine\error_handler(integer 2, string Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP), string phar:///plugins/DropdownUIEdited_v1.0.4.phar/src/ddui/Command/DropdownCMD.php, integer 26, array Array()) 14.02 00:25:55 [Server] Server thread/DEBUG #1 FormAPI_v1.0.0.phar/src/jojoe77777/FormAPI/FormAPI(84): ddui\Command\DropdownCMD->ddui\Command\{closure}(pocketmine\Player object, array Array()) 14.02 00:25:55 [Server] Server thread/DEBUG #2 src/pocketmine/plugin/MethodEventExecutor(38): jojoe77777\FormAPI\FormAPI->onPacketReceived(pocketmine\event\server\DataPacketReceiveEvent object) 14.02 00:25:55 [Server] Server thread/DEBUG #3 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(jojoe77777\FormAPI\FormAPI object, pocketmine\event\server\DataPacketReceiveEvent object) 14.02 00:25:55 [Server] Server thread/DEBUG #4 src/pocketmine/plugin/PluginManager(683): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\server\DataPacketReceiveEvent object) 14.02 00:25:55 [Server] Server thread/DEBUG #5 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(91): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\server\DataPacketReceiveEvent object) 14.02 00:25:55 [Server] Server thread/DEBUG #6 src/pocketmine/network/mcpe/protocol/BatchPacket(115): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\ModalFormResponsePacket object) 14.02 00:25:55 [Server] Server thread/DEBUG #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(92): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object) 14.02 00:25:55 [Server] Server thread/DEBUG #8 src/pocketmine/Player(2964): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object) 14.02 00:25:55 [Server] Server thread/DEBUG #9 src/pocketmine/network/mcpe/RakLibInterface(150): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object) 14.02 00:25:55 [Server] Server thread/DEBUG #10 vendor/pocketmine/raklib/server/ServerHandler(103): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 151.64.79.105:45328, raklib\protocol\EncapsulatedPacket object, integer 0) 14.02 00:25:55 [Server] Server thread/DEBUG #11 src/pocketmine/network/mcpe/RakLibInterface(89): raklib\server\ServerHandler->handlePacket() 14.02 00:25:55 [Server] Server thread/DEBUG #12 src/pocketmine/network/Network(89): pocketmine\network\mcpe\RakLibInterface->process() 14.02 00:25:55 [Server] Server thread/DEBUG #13 src/pocketmine/Server(2527): pocketmine\network\Network->processInterfaces() 14.02 00:25:55 [Server] Server thread/DEBUG #14 src/pocketmine/Server(2279): pocketmine\Server->tick() 14.02 00:25:55 [Server] Server thread/DEBUG #15 src/pocketmine/Server(2154): pocketmine\Server->tickProcessor() 14.02 00:25:55 [Server] Server thread/DEBUG #16 src/pocketmine/Server(1742): pocketmine\Server->start() 14.02 00:25:55 [Server] Server thread/DEBUG #17 src/pocketmine/PocketMine(551): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string /, string /plugins/) 14.02 00:25:55 [Server] Server thread/DEBUG #18 /jar/versions/PocketMine/PocketMine-MP659.phar(1): require(string phar:///jar/versions/PocketMine/PocketMine-MP659.phar/src/pocketmine/PocketMine.php)
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    You must foreach getOnlinePlayers();
     
    xXNiceAssassinlo YT likes this.
  4. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Done but doesnt work again
     
  5. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Didnt you see the error in the console?
     
  6. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    It sasys that $data isnt defined but it is defiened
     
  7. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Check your code again :(
    PHP:
    if(data[0] != null){
    After you, wath wrong here?
     
  8. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    The $ :) fixed but not working again ._.
     
  9. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Not working? plz explain more
     
  10. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    I chose the player i want and wrote the message but the player doesnt get the message.
     
  11. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Try that
    PHP:
    public function execute(CommandSender $senderstring $commandLabel, array $args){
            
    $api $this->getPlugin()->getServer()->getPluginManager()->getPlugin("FormAPI");
            if(
    $api === null){
                return 
    true;
            }
            
    $form $api->createCustomForm(function (Player $sender, array $data){
            
    $result $data[0];
            if(
    $result != null){
                
    $sender->sendMessage("data is null");
            }
            switch(
    $result){
                case 
    0:
                break;
                case 
    1:
                break;
            }
            });
            foreach (
    $this->getServer()->getOnlinePlayers() as $value){
                
    $nametag $value->getName();
            }
            
    $form->setTitle("");
            
    $form->addDropdown("Player Liste:", [$nametag]);
            
    $form->sendToPlayer($sender); 
        }
     
  12. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    You did not put an input
     
  13. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Where is the input? xd
     
  14. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    That will only provide the username of the last player, as you are changing $nametag in your foreach() statement each time.
     
  15. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    You could add each name to an array in your foreach statement or you could use the array_map function.

    Example 1
    PHP:
    $names = [];
    foreach (
    $this->getPlugin()->getServer()->getOnlinePlayers() as $player) {
        
    $names[] = $player->getName();
    }
    Example 2
    PHP:
    $names array_map(function ($player) {
        return 
    $player->getName();
    }, 
    $this->getPlugin()->getServer()->getOnlinePlayers());
     
    Last edited: Feb 15, 2018
  16. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    I'l try it thx
     
  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.