Hey in this code i try to get all player name in an Dropdown PHP: public function inviteSkyBlock(Player $player){ $players = $this->getServer()->getOnlinePlayers(); $ui = new CustomForm("",""); $Dropdown = new Dropdown("", array("§ln/a", $players->getName())); $ui->addElement($Dropdown); $pk = new ModalFormRequestPacket(); $pk->formId = 111; $pk->formData = json_encode($ui); $player->dataPacket($pk); return true; }
i have a question simular to this.... how can i get Slider data PHP: :public function BuyForm($id, $player){$api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");$form = $api->createCustomForm(function (Player $event, array $data){$result = $data[1];$player = $event->getPlayer();});$form->setTitle("Buy enchantment");$form->addSlider("Level", 1, 5, -1, -1);$form->sendToPlayer($player);}
PHP: if($result !== null){ $item->addEnchantment(Enchantment::getEnchantment($id)->setLevel($result)}
Such as PHP: public function inviteSkyBlock(Player $player){ $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!"); foreach($this->getServer()->getOnlinePlayers() as $online){ $name = $online->getName(); $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array("§ln/a", $name)); } var_dump($Dropdown); $ui->addElement($Dropdown); $pk = new ModalFormRequestPacket(); $pk->formId = 111; $pk->formData = json_encode($ui); $player->dataPacket($pk); return true; }
Or try this to send multiple buttons as you want I think PHP: public function inviteSkyBlock(Player $player){ $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!"); $Dropdown = ""; foreach($this->getServer()->getOnlinePlayers() as $online){ $name = $online->getName(); $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array("§ln/a", $name)); var_dump($Dropdown); $ui->addElement($Dropdown); $pk = new ModalFormRequestPacket(); $pk->formId = 111; $pk->formData = json_encode($ui); $player->dataPacket($pk); return true; } }
PHP: public function inviteSkyBlock(Player $player){ $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!"); foreach($this->getServer()->getOnlinePlayers() as $online){ $name = $online->getName(); $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array($name)); } $ui->addElement($Dropdown); $pk = new ModalFormRequestPacket(); $pk->formId = 111; $pk->formData = json_encode($ui); $player->dataPacket($pk); return true; } PHP: 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 === 111){ if($data === 0){ //$this->getServer()->dispatchCommand($player, "sb invite" . $player->getName($data[0])); $player->sendMessage("test"); return true; } } } } } Why nothing happen why ModalFormResponsePacket (No error)
Same thing whith FromAPI nothing happen PHP: public function inviteSkyBlock($player){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createCustomForm(function (Player $event, array $data){ $player = $event->getPlayer(); $result = $data[0]; if($result === null){ $player->sendMessage("test"); } switch($result){ case 0: $player->sendMessage("test"); break; case 1: $player->sendMessage("test"); break; } }); $form->setTitle("SkyBlock\ninvite"); foreach($this->getServer()->getOnlinePlayers() as $online){ $name = $online->getName(); $form->addDropdown("§lInvite a player from the bolow liste:", array($name)); } $form->sendToPlayer($player); }