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

Solved Help with Server Settings

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

  1. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Code
    PHP:
    <?php

    namespace ts;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
    use 
    pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
    use 
    pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket;
    use 
    pocketmine\Player;

    class 
    TestSettings extends PluginBase implements Listener {
      
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            if(!
    is_dir($this->getDataFolder())){
                
    mkdir($this->getDataFolder());
            }
            
    $this->saveResource("SettingsInfo.json");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
      
        public function 
    onPacket(DataPacketReceiveEvent $ev){
            
    $packet $ev->getPacket();
            if(
    $packet instanceof ServerSettingsRequestPacket){
                
    $packet = new ServerSettingsResponsePacket;
                
    $packet->formData file_get_contents($this->getDataFolder() . "SettingsInfo.json");
                
    $packet->formId 3491;
                
    $ev->getPlayer()->dataPacket($packet);
            } elseif(
    $packet instanceof ModalFormResponsePacket){
                
    $formId $packet->formId;
                if(
    $formId !== 3491){
                    return;
                }
                
    $formData = (array) json_decode($packet->formDatatrue);
                
    $msg $formData[1];
                
    $button $formData[2];
                if(!
    $button){
                    
    $ev->getPlayer()->sendMessage($msg);
                    return;
                }
            }
        }
    }
    ?>
    SettingsInfo.json
    Code:
    {
      "type": "custom_form",
      "title": "§eTest §aKhaled098yt",
      "icon": {
        "type": "url",
        "data": "https://minecraft.gamepedia.com/media/minecraft.gamepedia.com/9/9c/Skeleton_Skull.png"  
      },
      "content": [
        {
          "type": "label",
          "text": "Hello There!!"
        },
        {
          "type": "input",
          "text": "Message",
          "placeholder": "Msg"
        },
        {
          "type": "toggle",
          "text": "Send Message",
          "default": false
        }
      ]
    }
    
    It is working fine but when i click the toggle it doesnt send the player the message that was in the input.
     
  2. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    It comes to my attention that there aren't setting API plugins yet. Well, the answer to your question is: ModalFormResponsePacket -> ServerSettingsResponsePacket. It's your turn to figure out what else to correct in your code.

    Tip: Read what you code. Don't just copy and paste code snippets you found somewhere. I mean, it's good to do that in the learning process, but understanding what you are typing in your code editor.
     
    Last edited: Feb 26, 2018
  3. Keith

    Keith Spider Jockey

    Messages:
    42
    GitHub:
    k3ithos
    Citation needed, https://github.com/pmmp/PocketMine-...cpe/protocol/ServerSettingsResponsePacket.php

    My understanding from past experience is that when the client sends ServerSettingsRequestPacket, the server can send the form in ServerSettingsResponsePacket. Example of code you might use in DataPacketReceiveEvent:
    PHP:
    $form DefaultForms::sendProfileMenu($player$this->plugin$this->plugin->formHandler->handleProfileMenu());
    $pk = new ServerSettingsResponsePacket();
    $pk->formId $form[0];
    $pk->formData json_encode($form[1]);
    $player->dataPacket($pk);
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Sorry, I didn't exactly say the right thing there, but what kenygamer is saying is incorrect nonetheless. You use the ModalFormResponsePacket to collect the actual data of the form, which the poster of this thread did. The packets part is perfectly fine, it's just about the message not being sent if the toggle is toggled to true, which is because of the last if statement.
     
  5. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    I did not copy anything..
     
  6. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    What is wrong with the last if statment?
     
  7. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    That's right.
     
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You check if the toggle is not enabled, and if it's not enabled you send the message.
     
  9. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Ohhhh i set that if its not enabled it sends the message :facepalm: its okay guys it solved thank you
     
  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.