Created
July 11, 2020 02:46
-
-
Save PJZ9n/4ef6acc762bf8a7ceb257211c25cc205 to your computer and use it in GitHub Desktop.
FormでもConfigを使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use pocketmine\form\Form; | |
use pocketmine\Player; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\utils\Config; | |
class Main extends PluginBase | |
{ | |
/** @var Config */ | |
private $config; | |
public function onEnable(): void | |
{ | |
$this->config = new Config($this->getDataFolder() . "config.yml"); | |
} | |
public function foo(Player $player): void | |
{ | |
$player->sendForm(new ExampleForm($this->config)); | |
} | |
} | |
class ExampleForm implements Form | |
{ | |
/** @var Config */ | |
private $config; | |
public function __construct(Config $config) | |
{ | |
$this->config = $config; | |
} | |
public function handleResponse(Player $player, $data): void | |
{ | |
// TODO: Implement handleResponse() method. | |
} | |
public function jsonSerialize(): array | |
{ | |
$options = $this->config->get("options"); | |
return [ | |
"content" => [ | |
[ | |
"type" => "dropdown", | |
"text" => "選択してください", | |
"options" => $options, | |
], | |
], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment