EasyForms icon indicating copy to clipboard operation
EasyForms copied to clipboard

Need Improvements

Open Lycol50 opened this issue 4 years ago • 1 comments

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.

Lycol50 avatar Mar 29 '20 06:03 Lycol50

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.

xxAROX avatar Jul 02 '20 08:07 xxAROX