Code PHP: <?phpnamespace 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->formData, true); $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.
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.
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);
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.