how can i do foreach Online players it add a button in the UI and then when i click that button it store the name of the player in public Variable . PHP: public function test($player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, $data){ if($data === null){ return; } else { //What should i do here ? }); $form->setTitle("§7test§r"); $form->setContent("§aTesT "); foreach($this->getServer()->getOnlinePLayers as $f){ if(!$this->getServer()->getPlayerExact($f) == null){ $form->addButton("§e".$f ." \n» §7(§aOnline§7) §e«§r"); } } $form->addButton("§0Back§r"); $form->sendToPlayer($player); return $form; }
try with PHP: public function test($player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, $data){ if($data === null){ return; } else { }); $form->setTitle("§7test§r"); $form->setContent("§aTesT "); foreach($this->getServer()->getOnlinePlayers as $f){ if($f instanceof Player){ $form->addButton("§e".$f->getName() ." \n» §7(§aOnline§7) §e«§r"); } } $form->addButton("§0Back§r"); $form->sendToPlayer($player); return $form; }
TheOriginDevelopment you didn't understand what i want: When i open this UI it should add buttons foreach all online members and when i click any button it should store the name of that a player in a public variable
Oh okey srry try that : PHP: public function test($player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, $data){ if($data === null){ return; } else { switch($data){ default: $players = $this->getServer()->getOnlinePlayers(); $this->player = array_slice($players, $data); //$this->player = the player you clicked in the menu break;} }); $form->setTitle("§7test§r"); $form->setContent("§aTesT "); foreach($this->getServer()->getOnlinePlayers as $f){ if($f instanceof Player){ $form->addButton("§e".$f->getName() ." \n» §7(§aOnline§7) §e«§r"); } } $form->addButton("§0Back§r"); $form->sendToPlayer($player); return $form; }
it didn't work TheOriginDevelopment. i want the name of the player not the player and if i will use getName() it will not work because we can't call the function getName() on an array
i'm sorry TheOriginDevelopment . i know what's the problem with my work .when you do getOnlinePlayers but me i was using config and in the config there was a name of a player not a player .but can you help me please this is my real work PHP: public function TestUI($player) { $playerDis = $player->getPlayer(); $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createSimpleForm(function (Player $player, $data){ if($data === null){ return; } else{ $config = new Config($this->getDataFolder().'/players/'.$player->getName().".yml", Config::YAML); $this->TestTwoUI($player); $players = $config->get("test"); $this->test = array_slice($players, $data); } }); $config = new Config($this->getDataFolder().'/players/'.$player->getName().".yml", Config::YAML); $form->setTitle("§7Test§r"); $form->setContent("§aTest: "); if(empty($config->get("test"))){ $form->setContent("§4No one in the config!"); } else{ foreach($config->get("test") as $t){ if(!$this->getServer()->getPlayerExact($t) == null){ $form->addButton("§e".$t ." \n» §7(§aOnline§7) §e«§r"); } else{ $form->addButton("§e".$t ." \n» §7(§cOffline§7) §e«§r"); } } $form->addButton("§0Back§r"); $form->sendToPlayer($player); return $form; } } But it doesn't work correctly.
no i don't want in a dropdown i want it to be like buttons and i don't need online players because i'm using config now that store a name of a player when i do a command and when i click that button it store the name of a player in a private variable understand HiToLaKhanh ? any Otherone Can help