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 $sender, string $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; } } } }
Have you imported the ModalFormResponsePacket class? instanceof doesn't throw errors if the class doesn't exist, it silently returns false.
Yes of course PHP: <?phpnamespace 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\{ModalFormRequestPacket, ModalFormResponsePacket};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 $sender, string $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($data, true); 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; } } } }}
This work fine with that. -_- PHP: <?phpnamespace EasySkyBlock;use pocketmine\Player;use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat as TF;use pocketmine\command\{Command, CommandSender, ConsoleCommandSender, CommandExecutor};use pocketmine\event\server\DataPacketReceiveEvent;use pocketmine\network\mcpe\protocol\{ModalFormRequestPacket, ModalFormResponsePacket};class Main extends PluginBase implements Listener { public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onCommand(CommandSender $sender, Command $cmd, string $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; } } } }}