Skip to content

Conversation

IvanCraft623
Copy link
Contributor

@IvanCraft623 IvanCraft623 commented Jul 13, 2022

Introduction

This pull request will remove the limit for plugin developers to only set strings as labels.

Justification

In some cases, for example when the button references an object, it is necessary to make hacky or inefficient code to achieve the goal.

Example: A teleport form

Before:

$form = new SimpleForm(function (Player $player, ?string $result = null) {
	if ($result !== null) {
		$pl = $player->getServer()->getPlayerExact($result);
		if ($pl !== null) {
			$player->teleport($pl->getPosition());
		}
	}
});
$form->setTitle("Teleporter");
$form->setContent("Teleport you to another player position");
foreach ($player->getWorld()->getPlayers() as $pl) {
	$form->addButton($pl->getName(), -1, "", $pl->getName());
}
$form->sendToPlayer($player);

After:

$form = new SimpleForm(function (Player $player, ?Player $result = null) {
	if ($result !== null) {
		$player->teleport($result->getPosition());
	}
});
$form->setTitle("Teleporter");
$form->setContent("Teleport you to another player position");
foreach ($player->getWorld()->getPlayers() as $pl) {
	$form->addButton($pl->getName(), -1, "", $pl);
}
$form->sendToPlayer($player);

Backwards compatibility

This is technically BC Break as it requires at least PHP8, but since PM4 already requires PHP8 as a minimum there should be no problems.

IvanCraft623 and others added 3 commits July 13, 2022 12:17
Poggit-CI is enabled for this repo by @IvanCraft623
Visit the Poggit-CI page for this repo at https://poggit.pmmp.io/ci/IvanCraft623/FormAPI
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

Successfully merging this pull request may close these issues.

2 participants