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

SimpleForm: Allow mixed value on labels #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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