I fix m'y issu but i cant manage to target the name of PHP: public function confirmBuy($sender){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if($api === null || $api->isDisabled()){ } $form = $api->createCustomForm(function (Player $sender, array $data){ $result = $data[0]; if($result != null){ $sender->sendMessage("data is null"); } switch($result){ case 0: $this->targetname = $result; $this->reason = $data[1]; $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "kick " . $this->targetname . " " . $this->reason); break; case 1: break; } }); foreach ($this->getServer()->getOnlinePlayers() as $value){ $nametag = $value->getName(); } $form->setTitle(""); $form->addDropdown("Player Liste:", [$nametag]); $form->addInput("", "raison"); //$form->addSlider("Amount" , 1, 64, 1); $form->sendToPlayer($sender); } Console say that: PHP: [18:56:21] [Server thread/INFO]: That player cannot be found
False, you could get a list of players names and create a dropdown for each player. Not recommended on a production server.
I made an cache but i got undefined offset: PHP: public $cache = [];public function confirmBuy($sender){ $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if($api === null || $api->isDisabled()){ } $form = $api->createCustomForm(function (Player $sender, array $data){ $result = $data[0]; if($result != null){ $sender->sendMessage("data is null"); } switch($result){ case 0: //$this->targetname = $result; $this->reason = $data[1]; $this->getServer()->dispatchCommand(new ConsoleCommandSender, "kick " . $this->cache[$sender->getName()][($result)] . " " . $this->reason); break; case 1: break; } }); $form->setTitle(""); foreach($this->getServer()->getOnlinePlayers() as $online){ $name = $online->getName(); $this->cache[$sender->getName()][] = $name; } $form->addDropdown("Player Liste:", [$this->cache[$sender->getName()][]]); $form->addInput("", "raison"); $form->sendToPlayer($sender); }
If you were to pull a list of players and get their names for each UI that's opened it would drastically slow down the main thread if multiple UI's are being opened frequently. An ideal was to achieve that would be to create a gloabl array and push a players name to it on join and unset it when they disconnect/quit.
Huh? How can it slow down the main thread? If it does, creating a new PlayerMoveEvent for each player every tick is thousands times more laggy, right? How can mapping player list to a menu item list be laggy? Or does your form API do extra stuff every time a menu item is constructed?
Using FormsAPI (jojoe77777) I created a form with a dropdown with a list of 100 players names, It took 1.023 seconds to parse the array of players and push their name to a dropdown. There does seem to be a delay when using a plugin for Forms over the built-in forms (forms-api branch).