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

Try to get $data

Discussion in 'Development' started by armagadon159753, Mar 2, 2018.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Here when player click on 1 of 5 boutons
    Its send a message or other thing
    But nothing happen.
    I have already car_dump $data but the console displayed nothing

    PHP:
    public function MenuSB($player){
            
    $pk = new ModalFormRequestPacket();
            
    $form = array();
            
    $form["title"] = "SkyBlock";
            
    $form["type"] = "form";
            
    $form["content"] = "";
            
    $form["buttons"][] = ["text" => TextFormat::BLUE "Join"];
            
    $form["buttons"][] = ["text" => TextFormat::BLUE "Home"];
            
    $form["buttons"][] = ["text" => TextFormat::BLUE "Members"];
            
    $form["buttons"][] = ["text" => TextFormat::BLUE "Teleport"];
            
    $form["buttons"][] = ["text" => TextFormat::BLUE "Management"];
            
    $pk->formId 135;
            
    $pk->formData json_encode($form);
            
    $player->dataPacket($pk);
        }
      
        public function 
    execute(CommandSender $senderstring $commandLabel, array $args){
            
    $plugin $this->plugin;
            
    $config $plugin->getSkyBlockManager()->getPlayerConfig($sender);
            if(
    $sender instanceof Player){
                if(empty(
    $config->get("island"))){
                    
    $this->MenuSB($sender);
                }else{
                    
    //$this->MenuSB($sender);
                
    }
            }
        }
      
        public function 
    onDataPacketReceiveEvent(DataPacketReceiveEvent $event){
            
    $pk $event->getPacket();
            
    $player $event->getPlayer();
            if(
    $pk instanceof ModalFormResponsePacket){
                
    $id $pk->formId;
                
    $data $pk->formData;
                
    $data json_decode($data);
                
    var_dump($data);
                if(
    $data === Null) return true;
                if(
    $id === 135){
                    if(
    $data === Null){
                        
    $player->sendMessage("null");
                        return 
    true;
                    }
                    if(
    $data === 0){
                        
    $player->sendMessage("data 0");
                        return 
    true;
                    }
                    if(
    $data === 1){
                        
    $player->sendMessage("data 1");
                        return 
    true;
                    }
                    if(
    $data === 2){
                        
    $player->sendMessage("data 2");
                        return 
    true;
                    }
                }
            }
        }
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    add $data = $data[0]; before var_dump()
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    No change i have the same result "nothing"
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Have you imported the ModalFormResponsePacket class?

    instanceof doesn't throw errors if the class doesn't exist, it silently returns false.
     
  5. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Yes of course
    PHP:
    <?php

    namespace SkyBlock\command;

    use 
    SkyBlock\Utils;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    SkyBlock\invitation\Invitation;
    use 
    SkyBlock\island\Island;
    use 
    SkyBlock\SkyBlock;
    use 
    SkyBlock\reset\Reset;

    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\network\mcpe\protocol\{ModalFormRequestPacketModalFormResponsePacket};

    class 
    SkyBlockCommand extends Command {
       
        private 
    $plugin;
       
        public function 
    __construct(SkyBlock $plugin){
            
    $this->plugin $plugin;
            
    parent::__construct("skyblock""SkyBlock Command""Usage: /skyblock", ["sb"]);
        }

        public function 
    sendMessage(Player $sender$message){
            
    $sender->sendMessage("[SB] " $message);
        }
       
        public function 
    execute(CommandSender $senderstring $commandLabel, array $args){
            
    $plugin $this->plugin;
            
    $config $plugin->getSkyBlockManager()->getPlayerConfig($sender);
            if(
    $sender instanceof Player){
                if(empty(
    $config->get("island"))){
                    
    $pk = new ModalFormRequestPacket();
                    
    $form = array();
                    
    $form["title"] = "SkyBlock";
                    
    $form["type"] = "form";
                    
    $form["content"] = "";
                    
    $form["buttons"][] = ["text" => "Join"];
                    
    $form["buttons"][] = ["text" => "Home"];
                    
    $form["buttons"][] = ["text" => "Members"];
                    
    $form["buttons"][] = ["text" => "Teleport"];
                    
    $form["buttons"][] = ["text" => "Management"];
                    
    $pk->formId 110;
                    
    $pk->formData json_encode($form);
                    
    $sender->dataPacket($pk);
                }
            }
        }
       
        public function 
    DataPacketReceiveEvent(DataPacketReceiveEvent $event){
            
    $packet $event->getPacket();
            
    $player $event->getPlayer();
            if(
    $packet instanceof ModalFormResponsePacket){
                
    $id $packet->formId;
                
    $data $packet->formData;
                
    $data json_decode($datatrue);
                
    var_dump($data);
                if(
    $data === Null) return true;
                if(
    $id === 110){
                    
    $sender->sendMessage("Form sent");
                    if(
    $data === 0){
                        
    $sender->sendMessage("0");
                        return 
    true;
                    }
                    if(
    $data === 1){
                        
    $sender->sendMessage("1");
                        return 
    true;
                    }
                    if(
    $data === 2){
                        
    $sender->sendMessage("2");
                        return 
    true;
                    }
                }
            }
        }
    }
     
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    This work fine with that.
    -_-
    PHP:
    <?php
    namespace EasySkyBlock;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\command\{CommandCommandSenderConsoleCommandSenderCommandExecutor};

    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\network\mcpe\protocol\{ModalFormRequestPacketModalFormResponsePacket};

    class 
    Main extends PluginBase implements Listener {
       
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args): bool{
            switch(
    $cmd->getName()){
                case 
    "shop":
                if(
    $sender instanceof Player){
                    
    $pk = new ModalFormRequestPacket();
                    
    $form = array();
                    
    $form["title"] = "SkyBlock";
                    
    $form["type"] = "form";
                    
    $form["content"] = "";
                    
    $form["buttons"][] = ["text" => "Join"];
                    
    $form["buttons"][] = ["text" => "Home"];
                    
    $form["buttons"][] = ["text" => "Members"];
                    
    $form["buttons"][] = ["text" => "Teleport"];
                    
    $form["buttons"][] = ["text" => "Management"];
                    
    $pk->formId 200;
                    
    $pk->formData json_encode($form);
                    
    $sender->dataPacket($pk);
                }
            }
            return 
    true;
        }
       
        public function 
    DataPacketReceiveEvent(DataPacketReceiveEvent $event){
            
    $packet $event->getPacket();
            
    $player $event->getPlayer();
            if(
    $packet instanceof ModalFormResponsePacket){
                
    $id $packet->formId;
                
    $data $packet->formData;
                
    $data json_decode($data);
                if(
    $data === Null) return true;
                if(
    $id === 200){
                    if(
    $data === 0){
                            
    $player->sendMessage("data 0");
                        return 
    true;
                    }
                    if(
    $data === 1){
                            
    $player->sendMessage("data 1");
                        return 
    true;
                    }
                    if(
    $data === 2){
                            
    $player->sendMessage("data 2");
                        return 
    true;
                    }
                    if(
    $data === 3){
                            
    $player->sendMessage("data 3");
                        return 
    true;
                    }
                }
            }
        }
    }
     

    Attached Files:

  7. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Anyone can tell why please?:(
     
  8. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    What exactly are you trying to do
     
  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.