Skip to content

Latest commit

 

History

History
89 lines (82 loc) · 2.88 KB

README.md

File metadata and controls

89 lines (82 loc) · 2.88 KB

EasyForms

Plugin for pmmp that allow you create GUI in a few clicks.

Migrating to 1.0.6

- EasyForms::sendForm($player, $form);
//must be replaced to
+ $player->sendForm($form);
//and servers settings must be replaced to
+ $e->setForm($form);

Code samples

ModalForm

$sender->sendForm(new class("A small question", "Our server is cool?") extends ModalForm{
	public function onSubmit(Player $player, $response) : void{
		$player->sendMessage($response ? "Thank you" : "We will try to become better");
	}
});

modal

MenuForm

$sender->sendForm(new class("Select server", "Choose server", [
	new Button("SkyWars #1", "https://d1u5p3l4wpay3k.cloudfront.net/minecraft_gamepedia/1/19/Melon.png")
]) extends MenuForm{
	public function onSubmit(Player $player, $response) : void{
		parent::onSubmit($player, $response);
		$player->sendMessage("You selected: " . $this->buttons[$response]->getText());
	}
});

menu

CustomForm

$sender->sendForm(new class("Enter data", [
	new Dropdown("Select product", ["beer", "cheese", "cola"]),
	new Input("Enter your name", "Bob"),
	new Label("I am label!"), //popElement() does not work with label
	new Slider("Select count", 0.0, 100.0, 1.0, 50.0),
	new StepSlider("Select product", ["beer", "cheese", "cola"]),
	new Toggle("Creative", $sender->isCreative())
]) extends CustomForm{
	public function onSubmit(Player $player, $response) : void{
		parent::onSubmit($player, $response);
		/** @var Dropdown $dropdown */
		$dropdown = $this->popElement();
		$player->sendMessage("You selected: {$dropdown->getSelectedOption()}");

		/** @var Input $input */
		$input = $this->popElement();
		$player->sendMessage("Your name is {$input->getValue()}");

		/** @var Slider $slider */
		$slider = $this->popElement();
		$player->sendMessage("Count: {$slider->getValue()}");

		/** @var StepSlider $stepSlider */
		$stepSlider = $this->popElement();
		$player->sendMessage("You selected: {$stepSlider->getSelectedOption()}");

		/** @var Toggle $toggle */
		$toggle = $this->popElement();
		$player->setGamemode($toggle->getValue() ? 1 : 0);
	}
});

custom1 custom2

ServerSettingsForm

public function onServerSettingsRequest(ServerSettingsRequestEvent $e) : void{
	$player = $e->getPlayer();
	$e->setForm(new class("Server settings", [
		new Label("Some text"),
		new Toggle("Fly", $player->isFlying())
	], "http://icons.iconarchive.com/icons/double-j-design/diagram-free/128/settings-icon.png") extends ServerSettingsForm{
		public function onSubmit(Player $player, $response) : void{
			parent::onSubmit($player, $response);
			/** @var Toggle $toggle */
			$toggle = $this->popElement();
			$player->setAllowFlight((bool) $toggle->getValue());
		}
	});
}

settings