Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Improvements #28

Open
Lycol50 opened this issue Mar 29, 2020 · 1 comment
Open

Need Improvements #28

Lycol50 opened this issue Mar 29, 2020 · 1 comment

Comments

@Lycol50
Copy link

Lycol50 commented Mar 29, 2020

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
Copy link

xxAROX commented Jul 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants