Not everything will be added in order because the player needs permission for the option to appear, so even if I put several boxes inside, the button will say something and the box will do something else Code: ... options: OptionOne: This is the First Option OptionTwo: This is the Second Option //and more... ... PHP: public function OptionsF ($player) { $api = $this->getServer()->getPluginManager()->getPlugin ("FormAPI"); $form = $api->createSimpleForm (function (Player $player, int $data = null) { $result = $data; if($result === null) { return true; } switch($result) { // Add cases with "$options" // exemple: case $options: // would generate all the cases that would connect to the buttons. // another exemple: if($result === $options) {$player->sendMessage("Selected: ".$options);} caso 1: // $player->sendMessage("You selected the option: ".$options->get ("msg"); break; caso 2: //código break; // another cases... or no xD } }); // Edit Menu $form->setTitle("Options"); $config = $this->getConfig(); foreach(array_keys($config->get("options")) as $options) { if($player->hasPermission("option.".$options)) { $form->setContent("You options:"); // my configuration has 15 options and I intend to add more, I don't want to leave the giant code and that already solves $form->addButton($options); //Each button needs a "case", how can I make a case for each one in the same way that it was here? }else{ $form->setContent("You don't have option."); } } $form->sendToPlayer($player); return $form; }}
You can get all the options field in your array and foreach the keys to create button. Then inside the callback part array_values() the array and get the value by $result. ($value = $array[$result])