Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Last active May 10, 2020 13:05
Show Gist options
  • Save PJZ9n/caa9fec440889bbf5af3ac60fb581b9f to your computer and use it in GitHub Desktop.
Save PJZ9n/caa9fec440889bbf5af3ac60fb581b9f to your computer and use it in GitHub Desktop.
pocketmine\form\Formを使ったModalFormの処理
<?php
declare(strict_types=1);
namespace foo\bar;
use pocketmine\form\Form;
use pocketmine\Player;
class ExampleForm implements Form
{
/**
* フォームが送信された時に呼ばれる
*
* @param Player $player
* @param mixed $data
*/
public function handleResponse(Player $player, $data): void
{
if ($data === null) {
//×が押された(または閉じられた)場合
return;//ここで処理を終了する
}
if ($data === true) {
//button1のボタンが押されたときの処理
} else if ($data === false) {
//button2のボタンが押されたときの処理
}
}
/**
* フォームの内容を返す(定義)
*
* @return array
*/
public function jsonSerialize(): array
{
return [
"type" => "modal",
"title" => "タイトル",
"content" => "選んでください",
"button1" => "ボタン1",
"button2" => "ボタン2",
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment