Frago9876543210 / EasyForms

Plugin for pmmp that allow you create GUI in a few clicks.
GNU General Public License v3.0
59 stars 16 forks source link

Playars name in drop down #11

Closed ghost closed 6 years ago

ghost commented 6 years ago

How do i add each player to drop down


        foreach(Ban::getInstance()->getServer()->getOnlinePlayers() as $online){
            $name .=   $online->getName();
        }
            EasyForms::sendForm($player, new class("Ban", [
                new Dropdown("Players", ["{$name}"],0),```
XDqrkneZ commented 6 years ago

just make $name an array

Frago9876543210 commented 6 years ago
$players = [];
foreach($player->getServer()->getOnlinePlayers() as $onlinePlayer){
    if($onlinePlayer !== $player){
        $players[] = $onlinePlayer->getName();
    }
}

And put $players to dropdown

Frago9876543210 commented 6 years ago
<?php

declare(strict_types=1);

namespace NS;

use Frago9876543210\EasyForms\EasyForms;
use Frago9876543210\EasyForms\elements\custom\Dropdown;
use Frago9876543210\EasyForms\forms\CustomForm;
use pocketmine\Player;
use pocketmine\utils\TextFormat;

class ChoosePlayer extends CustomForm{

    public function __construct(array $players){
        parent::__construct("Choose a player", [
            new Dropdown("Player", $players)
        ]);
    }

    public function onSubmit(Player $player, $response) : void{
        parent::onSubmit($player, $response);
        /** @var Dropdown $dropdown */
        $dropdown = $this->popElement();
        if(($target = $player->getServer()->getPlayer($targetName = $dropdown->getSelectedOption())) instanceof Player){
            //TODO
        }else{
            $player->sendMessage(TextFormat::YELLOW . "Player leave");
        }
    }
}