Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created July 11, 2020 02:46
Show Gist options
  • Save PJZ9n/4ef6acc762bf8a7ceb257211c25cc205 to your computer and use it in GitHub Desktop.
Save PJZ9n/4ef6acc762bf8a7ceb257211c25cc205 to your computer and use it in GitHub Desktop.
FormでもConfigを使う
<?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