Open Lycol50 opened 4 years ago
Here is a little help(its from my bedwars team selection)
$arena = $player->getArena();
if (!$arena instanceof Arena) {
$player->sendMessage("message.notInGame");
return;
}
$buttons = $arr = [];
foreach ($arena->getTeams() as $team) {
$name = $team->getColor() . $team->getName() . " | " . count($team->getPlayers()) . "/" . $team->getMaxPlayers();
$buttons[] = new Button($name);
$arr[$name] = $team;
}
$player->sendForm(new MenuForm( //FORM BEGINS
"Teams",
"",
$buttons,
function (Player $player, Button $button) use ($arr): void{ //FORM RESPONSE BEGINS
if (!$player instanceof BWPlayer) {
return;
}
/** @var Team $selectedTeam */
$selectedTeam = $arr[$button->getText()];
$oldTeam = $player->getTeam();
if ($oldTeam->getName() == $selectedTeam->getName()) {
$player->sendMessage("message.alreadyInTeam");
return;
}
if (count($selectedTeam->getPlayers()) >= $selectedTeam->getMaxPlayers()) {
$player->sendMessage("message.teamIsFull");
return;
}
$oldTeam->removePlayer($player);
$selectedTeam->addPlayer($player);
$player->sendMessage("message.onTeamChoose", [$selectedTeam->getColor() . $player->translate($selectedTeam->getName())]);
} //FORM RESPONSE ENDS
)); //FORM ENDS
i hope this can help you.
How to send the response to a specified api for example i am creating a form for voting of candidates for minecraft government? and the users will vote for the election.