Frago9876543210 / EasyForms

Plugin for pmmp that allow you create GUI in a few clicks.
GNU General Public License v3.0
59 stars 16 forks source link

Need Improvements #28

Open Lycol50 opened 4 years ago

Lycol50 commented 4 years ago

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.

xxAROX commented 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.