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: <?phpnamespace 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($command, DropdownUI $plugin){ parent::__construct($command, $plugin); } public function execute(CommandSender $sender, string $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.
And i got the error from the console: PHP: 00:25:55 [Server] Server 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 PHP) on jojoe77777\FormAPI\FormAPI 14.02 00:25:55 [Server] Server thread/CRITICAL ErrorException: "Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP)" (EXCEPTION) in "DropdownUIEdited_v1.0.4.phar/src/ddui/Command/DropdownCMD" at line 26 14.02 00:25:55 [Server] Server 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)
Try that PHP: public function execute(CommandSender $sender, string $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); }
That will only provide the username of the last player, as you are changing $nametag in your foreach() statement each time.
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());