
<?php
echo "PocketMine-MP plugin AccessInside v1.0.1
This file has been generated using DevTools v1.13.0 at Sat, 01 Dec 2018 16:40:46 +0900
----------------
";

if(extension_loaded("phar")){
	$phar = new \Phar(__FILE__);
	foreach($phar->getMetadata() as $key => $value){
		echo ucfirst($key) . ": " . (is_array($value) ? implode(", ", $value) : $value) . "\n";
	}
}

__HALT_COMPILER(); ?>
0             ú   a:9:{s:4:"name";s:12:"AccessInside";s:7:"version";s:5:"1.0.1";s:4:"main";s:25:"accessinside\AccessInside";s:3:"api";s:5:"3.2.1";s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1543650046;}
   plugin.ymlc   þ:\c   Z¬=s¶      !   src/accessinside/AccessInside.php  þ:\  ßaPx¶      (   src/accessinside/command/MainCommand.phpá  þ:\á  3l¶      %   src/accessinside/event/BreakEvent.php	  þ:\	  =ë½¶      %   src/accessinside/event/TouchEvent.phpe  þ:\e  Ð«˜T¶         src/accessinside/form/Forms.php‘   þ:\‘   e{ò¶      "   src/accessinside/form/OpenForm.phpç  þ:\ç  ¥43†¶      &   src/accessinside/password/Password.php  þ:\  =ž@ò¶      "   src/accessinside/task/CoolDown.phpZ  þ:\Z  ºK5¶      )   src/tokyo/pmmp/libform/element/Button.phpQ  þ:\Q  Iz„¶      +   src/tokyo/pmmp/libform/element/Dropdown.php^
  þ:\^
  )_Ý¶      *   src/tokyo/pmmp/libform/element/Element.php
  þ:\
  6ñN0¶      (   src/tokyo/pmmp/libform/element/Image.php»  þ:\»  qÐ¸™¶      (   src/tokyo/pmmp/libform/element/Input.phpØ  þ:\Ø  f/…¶      (   src/tokyo/pmmp/libform/element/Label.php=  þ:\=  0]~å¶      )   src/tokyo/pmmp/libform/element/Slider.phph
  þ:\h
  WÒ±È¶      -   src/tokyo/pmmp/libform/element/StepSlider.phpd
  þ:\d
  X†È¶      )   src/tokyo/pmmp/libform/element/Toggle.php£  þ:\£  khÏ¶      (   src/tokyo/pmmp/libform/EventListener.phpr  þ:\r  >|Z’¶      *   src/tokyo/pmmp/libform/form/CustomForm.php)  þ:\)  ë¦Û¶      $   src/tokyo/pmmp/libform/form/Form.phpé  þ:\é  Û+o¶      (   src/tokyo/pmmp/libform/form/ListForm.php@  þ:\@  È(Ðm¶      )   src/tokyo/pmmp/libform/form/ModalForm.phpM  þ:\M  ø>µ§¶      "   src/tokyo/pmmp/libform/FormApi.php<  þ:\<  dPìB¶      name: AccessInside
main: accessinside\AccessInside
version: 1.0.1
api: 3.2.1
author: metowa1227<?php
/**
 * ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã¨ã¯ã€ã“ã®ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ã§ä½¿ç”¨ã•ã‚Œã‚‹ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ä»˜ãã®ãƒ–ãƒ­ãƒƒã‚¯ã§ã€ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’è§£é™¤ã™ã‚‹ã“ã¨ã«ã‚ˆã‚Šä¸­ã«å…¥ã‚Œã‚‹ã¨ã„ã†ã‚‚ã®ã§ã™ã€‚
 * å‹æ‰‹ã«æ±ºã‚ã¾ã—ãŸã€‚
*/

namespace accessinside;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use accessinside\event\{
	TouchEvent,
	BreakEvent
};
use accessinside\command\MainCommand;

class AccessInside extends PluginBase
{
	/** @var TaskScheduler */
	private static $scheduler;

	public function onEnable()
	{
		//ã‚¤ãƒ™ãƒ³ãƒˆç™»éŒ²
		$this->getServer()->getPluginManager()->registerEvents(new TouchEvent($this, $this->getDataFolder()), $this);
		$this->getServer()->getPluginManager()->registerEvents(new BreakEvent(), $this);
		//Configç”Ÿæˆ
		if (!is_dir($this->getDataFolder())) {
			@mkdir($this->getDataFolder());
		}
		$config = new Config($this->getDataFolder() . "Config.yml", Config::YAML, ["op-only" => true]);
		//ã‚³ãƒžãƒ³ãƒ‰ç™»éŒ²
		$this->getServer()->getCommandMap()->register("acin", new MainCommand($config));
		self::$scheduler = $this->getScheduler();
	}

	/**
	 * ã‚¹ã‚±ã‚¸ãƒ¥ãƒ¼ãƒ©ã‚’å–å¾—ã™ã‚‹
	*/
	public static function getTaskScheduler()
	{
		return self::$scheduler;
	}
}
<?php
namespace accessinside\command;

use pocketmine\command\{
	Command,
	CommandSender
};
use pocketmine\Player;
use pocketmine\utils\Config;
use accessinside\event\TouchEvent;

class MainCommand extends Command
{
    public function __construct(Config $config)
    {
        parent::__construct("acin", "Register accessinside block", "/acin");
        $this->setPermission("command.acin");
        $this->config = $config;
    }

    public function execute(CommandSender $sender, string $label, array $args) : bool
    {
    	if (!$sender instanceof Player) {
    		$sender->sendMessage("ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã¯å®Ÿè¡Œã§ãã¾ã›ã‚“ã€‚");
    		return true;
    	}
    	if ($this->config->get("op-only")) {
    		if (!$sender->isOp()) {
    			$sender->sendMessage("ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã¯OPã®ã¿è¨­ç½®å¯èƒ½ã§ã™ã€‚");
    			return true;
    		}
    	}
    	TouchEvent::registerBlock($sender);
    	return true;
    }
}
<?php
namespace accessinside\event;

use pocketmine\event\Listener;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\level\particle\DestroyBlockParticle;
use accessinside\form\OpenForm;
use accessinside\event\TouchEvent;

class BreakEvent extends OpenForm implements Listener
{
	/**
	 * ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›ã®ç¶šã
	 *
	 * @param Player $player
	 * @param Event  $event
	 * @param bool   $isSuccess
	 *
	 * @return void
	*/
	public function continueEnterPassword(Player $player, BlockBreakEvent $event, bool $isSuccess) : void
	{
		if ($isSuccess) {
			$this->breaking = true;
			$block = $event->getBlock();
			$pos = floor($block->x) . " : " . floor($block->y) . " : " . floor($block->z) . " : " . $block->getLevel()->getName();
			TouchEvent::removeData($this, $pos);
			$block->getLevel()->setBlock(new Vector3($block->x, $block->y, $block->z), new Block(0, 0, 0));
			$block->getLevel()->addParticle(new DestroyBlockParticle($block->add(0.5, 0.5, 0.5), $block));
			$drops = $event->getDrops();
			if (!empty($drops)) {
				$dropPos = $block->add(0.5, 0.5, 0.5);
				foreach ($drops as $drop) {
					if (!$drop->isNull()) {
						$block->getLevel()->dropItem($dropPos, $drop);
					}
				}
			}
			$player->sendMessage("ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ç ´å£Šã—ã¾ã—ãŸã€‚");
			return;
		}
		$player->sendMessage("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ãŒä¸€è‡´ã—ã¾ã›ã‚“ã§ã—ãŸã€‚");
		return;
	}

	public function onBreak(BlockBreakEvent $event)
	{
		$player = $event->getPlayer();
		$name = $player->getName();
		$block = $event->getBlock();
		//ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‹ã©ã†ã‹
		if (!TouchEvent::isInsideBlock($block)) {
			return;
		}
		$pos = floor($block->x) . " : " . floor($block->y) . " : " . floor($block->z) . " : " . $block->getLevel()->getName();
		//ãƒ‡ãƒ¼ã‚¿å–å¾—
		$data = TouchEvent::getData()->get($pos);
		//ä½œæˆè€…ã‹ã©ã†ã‹
		if ($data["Owner"] !== $name) {
			$player->sendMessage("ä»–äººã®ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ç ´å£Šã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“ã€‚");
			$event->setCancelled();
			return;
		}
		//ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›
		$this->openForm($player, OpenForm::ENTER_PASSWORD, $data, $event);
		$event->setCancelled();
		return;
	}
}
<?php
namespace accessinside\event;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\utils\Config;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use accessinside\form\OpenForm;
use accessinside\AccessInside;

class TouchEvent extends OpenForm implements Listener
{
	/** @var bool */
	protected static $processingRegister;
	/** @var Config */
	protected static $data;

	public function __construct($caller, string $path = "")
	{
		if ($caller instanceof AccessInside) {
			self::$data = new Config($path . "InsideBlocks.yml", Config::YAML);
		} elseif ($caller instanceof OpenForm) {
			//nothing to do.
		}
	}

	/**
	 * ãƒ­ãƒƒã‚¯ä»˜ãã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ç™»éŒ²ã™ã‚‹
	 *
	 * @param Player $player
	 *
	 * @return void
	*/
	public static function registerBlock(Player $player) : void
	{
		$name = $player->getName();
		$player->sendMessage(">> ç™»éŒ²ã—ãŸã„ãƒ–ãƒ­ãƒƒã‚¯ã‚’ã‚¿ãƒƒãƒã—ã¦ãã ã•ã„ã€‚");
		self::$processingRegister[$name] = true;
	}

	public function onTouch(PlayerInteractEvent $event)
	{
		$player = $event->getPlayer();
		$name = $player->getName();
        $block = $event->getBlock();
        //ç ´å£Šè¡Œç‚ºã ã£ãŸã‚‰
        if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
        	return;
        }
		//registerBlockã®å‡¦ç†ãŒã‚ã‚‹ã‹
		if (isset(self::$processingRegister[$name])) {
			$this->continueProcessingRegister($player, $block);
			//ãƒã‚°é˜²æ­¢ã®ãŸã‚å‡¦ç†çµ‚äº†
			return;
		}
		//ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‹ã©ã†ã‹
		if (!self::isInsideBlock($block)) {
			return;
		}
		$pos = floor($block->x) . " : " . floor($block->y) . " : " . floor($block->z) . " : " . $block->getLevel()->getName();
		$data = self::$data->get($pos);
		//ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›ãŒä¸è¦ãªè¨­å®šã®å ´åˆ
		if ($data["DisableOwner"] && ($data["Owner"] === $name)) {
			$this->goToInside($player, $block);
			return;
		}
		//ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›
		$this->openForm($player, OpenForm::ENTER_PASSWORD, $data, $block);
		return;
	}

	/**
	 * ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›ã®ç¶šã
	 *
	 * @param Player $player
	 * @param Block  $block
	 * @param bool   $isSuccess
	 *
	 * @return void
	*/
	public function continueEnterPassword(Player $player, Block $block, bool $isSuccess) : void
	{
		if ($isSuccess) {
			$this->goToInside($player, $block);
			return;
		}
		$player->sendMessage("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ãŒä¸€è‡´ã—ã¾ã›ã‚“ã§ã—ãŸã€‚");
	}

	/**
	 * ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã®ç™»éŒ²ã®ç¶šã
	 *
	 * @param Player $player
	 * @param Block  $block
	 *
	 * @return void
	*/
	private function continueProcessingRegister(Player $player, Block $block) : void
	{
		$name = $player->getName();
		//æ—¢ã«ç”Ÿæˆæ¸ˆã¿ã ã£ãŸã‚‰
		if (self::isInsideBlock($block)) {
			$player->sendMessage("æ—¢ã«ç™»éŒ²æ¸ˆã¿ã®ãƒ–ãƒ­ãƒƒã‚¯ã§ã™ã€‚");
			return;
		}
		//ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’æ±ºã‚ã‚‹
		$this->openForm($player, OpenForm::REGISTER_BLOCK, $block);
		return;
	}

	/**
	 * ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›å¾Œã®å†å‡¦ç†
	 *
	 * @param Player $player
	 * @param        $password
	 * @param bool   $disableOwner
	 * @param Block  $block
	 *
	 * @return void
	*/
	public function reContinueProcessingRegister(Player $player, $password, bool $disableOwner, Block $block) : void
	{
		$name = $player->getName();
        //ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã®æƒ…å ±ã‚’ä¿å­˜
		$pos = floor($block->x) . " : " . floor($block->y) . " : " . floor($block->z) . " : " . $block->getLevel()->getName();
		$data = [
			"Password" => password_hash($password, PASSWORD_DEFAULT),
			"Owner" => $name,
			"DisableOwner" => (bool) $disableOwner
		];
		//ãƒ‡ãƒ¼ã‚¿ã®ä¿å­˜
        self::$data->set($pos, $data);
        self::$data->save();
        $player->sendMessage("ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ä½œæˆã—ã¾ã—ãŸã€‚");
        $player->sendMessage("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã¯ " . $password . " ã§ã™ã€‚");
        $player->sendMessage("ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã®å‰å¾Œã«ã¯ãƒ–ãƒ­ãƒƒã‚¯ã‚’ç½®ã‹ãªã„ã‚ˆã†ã«ã—ã¦ãã ã•ã„ã€‚");
        //ä¸€æ™‚ãƒ‡ãƒ¼ã‚¿å‰Šé™¤
        unset(self::$processingRegister[$name]);
        return;
	}

	/**
	 * ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‹ã©ã†ã‹èª¿ã¹ã‚‹
	 *
	 * @param Block $block
	 *
	 * @return bool
	*/
	public static function isInsideBlock(Block $block) : bool
	{
		$pos = floor($block->x) . " : " . floor($block->y) . " : " . floor($block->z) . " : " . $block->getLevel()->getName();
		return self::$data->exists($pos);
	}

	/**
	 * BreakEventç”¨ã®ãƒ‡ãƒ¼ã‚¿å–å¾—é–¢æ•°
	 *
	 * @return Config
	*/
	public static function getData() : Config
	{
		return self::$data;
	}

	/**
	 * ãƒ‡ãƒ¼ã‚¿å‰Šé™¤
	 *
	 * @param $caller
	 * @param string $data
	*/
	public static function removeData($caller, $data) : void
	{
		if (!$caller instanceof BreakEvent) {
			return;
		}
		self::$data->remove($data);
		self::$data->save();
	}

	/**
	 * ã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ä½¿ç”¨ã—ã¦ä¸­ã«å…¥ã‚‹
	 *
	 * @param Player $player
	 * @param Block  $block
	 *
	 * @return void
	*/
	private function goToInside(Player $player, Block $block) : void
	{
		switch ($player->getDirection()) {
			//æ±
			case 0:
				$pos = new Vector3($block->x + 2.2, $block->y, $block->z);
				break;
			//åŒ—
			case 1:
				$pos = new Vector3($block->x, $block->y, $block->z + 2.2);
				break;
			//è¥¿
			case 2:
				$pos = new Vector3($block->x - 2.2, $block->y, $block->z);
				break;
			//æ±
			case 3:
				$pos = new Vector3($block->x, $block->y, $block->z - 2.2);
				break;
		}
        $player->teleport($pos);
	}
}
<?php
namespace accessinside\form;

interface Forms
{
	/** @var int FormType */
	const REGISTER_BLOCK = 0;
	const ENTER_PASSWORD = 1;
}
<?php
namespace accessinside\form;

use pocketmine\Player;
use pocketmine\Task;
use pocketmine\block\Block;
use accessinside\password\Password;
use accessinside\task\CoolDown;
use accessinside\AccessInside;
use accessinside\event\{
	TouchEvent,
	BreakEvent
};
use tokyo\pmmp\libform\{
    FormApi,
    element\Button,
    element\Input,
    element\Label,
    element\Toggle
};

class OpenForm implements Forms
{
	/** @var bool */
	public static $cooldown;
	/** @var Block */
	public $block;
	/** @var array */
	public $dataTmp;

	/**
	 * ãƒ•ã‚©ãƒ¼ãƒ ã‚’å±•é–‹ã™ã‚‹
	 *
	 * @param Player $player
	 * @param int $type
	 *
	 * @return array | bool
	*/
	public function openForm(Player $player, int $type, $option, $secondOption = null)
	{
		$name = $player->getName();
		if (isset(self::$cooldown[$name])) {
			return;
		}
		self::$cooldown[$name] = true;
		AccessInside::getTaskScheduler()->scheduleDelayedTask(new CoolDown($name), 5);
		switch ($type) {
			case self::REGISTER_BLOCK:
				return $this->registerBlockForm($player, $option); //option: Block
			case self::ENTER_PASSWORD:
				return $this->enterPassword($player, $option, $secondOption); //option: array, secondOption: Block or BlockBreakEvent
		}
    }

    /**
     * ãƒ–ãƒ­ãƒƒã‚¯ç™»éŒ²ãƒ•ã‚©ãƒ¼ãƒ ã‚’å±•é–‹ã™ã‚‹
     *
     * @param Player $player
     * @param Block  $block
     *
     * @return void
    */
    private function registerBlockForm(Player $player, Block $block) : void
    {
    	$this->block[$player->getName()] = $block;
        FormApi::makeCustomForm(
            function (Player $player, ?array $response) {
            	//ãƒ•ã‚©ãƒ¼ãƒ ãŒé–‰ã˜ã‚‰ã‚Œã¦ã„ã‚‹ã‹
                if (FormApi::formCancelled($response)) {
                    return;
                }
                //ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ãŒç©ºã ã£ãŸã‚‰
                if ($response[0] === "") {
                	$player->sendMessage("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„ã€‚");
                	return;
                }
                $touch = new TouchEvent($this);
                $touch->reContinueProcessingRegister($player, $response[0], $response[1], $this->block[$player->getName()]);
                unset($this->block[$player->getName()]);
                return;
            }
        )
        ->addElement(new Input("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„ã€‚", "ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰"))
        ->addElement(new Toggle("è‡ªåˆ†ã¯ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’å…¥åŠ›ã—ãªãã¦ã‚‚å…¥ã‚Œã‚‹ã‚ˆã†ã«ã™ã‚‹ã‹\næ³¨æ„: ã“ã®æ©Ÿèƒ½ã‚’æœ‰åŠ¹ã«ã™ã‚‹ã¨å®‰å…¨æ€§ãŒä½Žä¸‹ã—ã¾ã™ã€‚", false))
        ->setTitle("ãƒ­ãƒƒã‚¯ä»˜ãã‚¤ãƒ³ã‚µã‚¤ãƒ‰ãƒ–ãƒ­ãƒƒã‚¯ã‚’ä½œæˆ")
        ->sendToPlayer($player);
    }

    /**
     * ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›ãƒ•ã‚©ãƒ¼ãƒ 
     *
     * @param Player $player
     * @param array  $data
     * @param Block | BlockBreakEvent $option
     *
     * @return void
    */
    private function enterPassword(Player $player, array $data, $option) : void
    {
    	$this->dataTmp[$player->getName()] = $data;
    	$this->blockTmp[$player->getName()] = $option;
        FormApi::makeCustomForm(
            function (Player $player, ?array $response) {
            	//ãƒ•ã‚©ãƒ¼ãƒ ãŒé–‰ã˜ã‚‰ã‚Œã¦ã„ã‚‹ã‹
                if (FormApi::formCancelled($response)) {
                    return;
                }
                if ($this instanceof TouchEvent) {
	                $touch = new TouchEvent($this);
	                $touch->continueEnterPassword($player, $this->blockTmp[$player->getName()], Password::verifyPassword($this, $response[0], $this->dataTmp[$player->getName()]["Password"]));
	            } elseif ($this instanceof BreakEvent) {
	                $break = new BreakEvent();
	                $break->continueEnterPassword($player, $this->blockTmp[$player->getName()], Password::verifyPassword($this, $response[0], $this->dataTmp[$player->getName()]["Password"]));	            	
	            }
                unset($this->dataTmp[$player->getName()], $this->blockTmp[$player->getName()]);
            }
        )
        ->addElement(new Input("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„ã€‚", "ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰"))
        ->setTitle("ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰å…¥åŠ›")
        ->sendToPlayer($player);
    }
}
<?php
namespace accessinside\password;

use accessinside\event\{
	TouchEvent,
	BreakEvent
};

class Password
{
	/**
	 * ãƒ‘ã‚¹ãƒ¯ãƒ¼ãƒ‰ãŒä¸€è‡´ã™ã‚‹ã‹æ¤œè¨¼ã™ã‚‹
	 *
	 * @param object $caller
	 * @param $password
	 * @param $passwordData
	 *
	 * @return bool
	*/
	public static function verifyPassword($caller, $password, $passwordData) : bool
	{
		if (!$caller instanceof TouchEvent && !$caller instanceof BreakEvent) {
			return false;
		}
		return password_verify($password, $passwordData);
	}
}
<?php
namespace accessinside\task;

use pocketmine\scheduler\Task;
use accessinside\form\OpenForm;

class CoolDown extends Task
{
	/** @var string */
	private $name;

	public function __construct(string $name)
	{
		$this->name = $name;
	}

	public function onRun(int $tick)
	{
		unset(OpenForm::$cooldown[$this->name]);
	}
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * ButtonClass
 */
class Button extends Element {

  /** @var string */
  public const IMAGE_TYPE_PATH = "path";
  public const IMAGE_TYPE_URL = "url";

  /** @var string */
  protected $imageType = "";
  /** @var string */
  protected $imagePath = "";
  /** @var string */
  public $text = "";

  public function setImage(string $imagePath, string $imageType = self::IMAGE_TYPE_PATH): Button {
    switch ($imageType) {
      case self::IMAGE_TYPE_PATH:
      case self::IMAGE_TYPE_URL:
        $this->imagePath = $imagePath;
        $this->imageType = $imageType;
      break;

      default:
        throw new \InvalidArgumentException("The image type must be an string value Button::IMAGE_TYPE_PATH or Button::IMAGE_TYPE_URL");
      break;
    }
    return $this;
  }

  final public function format(): array {
    $data = [
      Form::KEY_TEXT => $this->text
    ];
    if (!empty($this->imageType)) {
      $data[Form::KEY_IMAGE] = [
        Form::KEY_TYPE => $this->imageType,
        Form::KEY_DATA => $this->imagePath
      ];
    }
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * DropdownClass
 */
class Dropdown extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "dropdown";

  /** @var string[] */
  protected $options = [];
  /** @var int */
  protected $defaultKey = 0;

  public function __construct(string $text, array $options = []) {
    parent::__construct($text);
    $this->options = $options;
  }

  public function getOption(int $key): ?string {
    return isset($this->options[$key])? $this->options[$key] : null;
  }

  public function addOption(string $option, $isDefault = false): Dropdown {
    $this->defaultKey = $isDefault ? count($this->options) : $this->defaultKey;
    $this->options[] = $option;
    return $this;
  }

  public function removeOption(string $option): Dropdown {
    $flip = array_flip($this->options);
    if (array_key_exists($option, $flip)) {
      $key = $flip[$option];
      unset($this->options[$key]);
    }
    return $this;
  }

  public function getDefault(): string {
    return empty($this->options)? "" : $this->options[$this->defaultKey];
  }

  public function setDefault(string $option): Dropdown {
    $flip = array_flip($this->options);
    if (array_key_exists($option, $flip)) {
      $key = $flip[$option];
      $this->defaultKey = $key;
    }else {
      throw new \OutOfRangeException("Invalid option " . $option);
    }
  }

  final public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text,
      Form::KEY_OPTIONS => $this->options,
      Form::KEY_DEFAULT => $this->defaultKey
    ];
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

/**
 * AbstractElementClass
 */
abstract class Element {

  /** @var string */
  protected const ELEMENT_NAME = "";

  /** @var string */
  protected $text = "";

  public function __construct(string $text) {
    $this->text = $text;
  }

  abstract public function format(): array;
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * ImageClass
 */
class Image extends Element {
  // TODO: #BlameMojang DOES NOT WORK

  final public function format(): array {
    return [];
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * InputClass
 */
class Input extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "input";

  /** @var string */
  protected $placeholder = "";
  /** @var string */
  protected $defaultText = "";

  public function __construct(string $text, string $placeholder, string $defaultText = "") {
    parent::__construct($text);
    $this->placeholder = $placeholder;
    $this->defaultText = $defaultText;
  }

  final public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text,
      Form::KEY_PLACEHOLDER => $this->placeholder,
      Form::KEY_DEFAULT => $this->defaultText
    ];
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * LabelClass
 */
class Label extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "label";

  final public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text
    ];
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * SliderClass
 */
class Slider extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "slider";

  /** @var number */
  protected $min = 0;
  /** @var number */
  protected $max = 0;
  /** @var number */
  protected $step = 0;
  /** @var number */
  protected $defaultValue;

  /**
   * @param string $text
   * @param number $min
   * @param number $max
   * @param int $step
   */
  public function __construct(string $text, $min, $max, $step = 0) {
    if ($min > $max) throw new \InvalidArgumentException("Minimum value must be less than maximum value");
    parent::__construct($text);
    $this->min = $min;
    $this->max = $max;
    $this->defaultValue = $min;
    $this->setStep($step);
  }

  public function setStep($step): Slider {
    if ($step < 0) throw new \InvalidArgumentException("The value of the step must be a positive value");
    $this->step = $step;
    return $this;
  }

  public function setDefaultValue($value): Slider {
    if ($value < $this->min || $value > $this->max) {
      throw new \InvalidArgumentException("The default value must be between the minimum and maximum values");
    }
    $this->defaultValue = $value;
    return $this;
  }

  final public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text,
      Form::KEY_MIN => $this->min,
      Form::KEY_MAX => $this->max,
    ];
    if ($this->step > 0) $data[Form::KEY_STEP] = $this->step;
    if ($this->defaultValue !== $this->min) {
      $data[Form::KEY_DEFAULT] = $this->defaultValue;
    }
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * StepSliderClass
 */
class StepSlider extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "step_slider";

  /** @var string[] */
  protected $steps = [];
  /** @var int */
  protected $defaultKey = 0;

  public function __construct(string $text, array $steps = []) {
    parent::__construct($text);
    $this->steps = $steps;
  }

  public function getStep(int $key): ?string {
    return isset($this->steps[$key])? $this->steps[$key] : null;
  }

  public function addStep(string $stepText, bool $isDefault = false): StepSlider {
    if ($isDefault) $this->defaultKey = count($this->steps);
    $this->steps[] = $stepText;
    return $this;
  }

  public function removeStep(string $stepText): StepSlider {
    $flip = array_flip($this->steps);
    if (array_key_exists($stepText, $flip)) {
      $key = $flip[$stepText];
      unset($this->steps[$key]);
    }
    return $this;
  }

  public function getDefaultStep(): string {
    return empty($this->steps)? "" : $this->steps[$this->defaultKey];
  }

  public function setDefaultStep(string $stepText): StepSlider {
    $flip = array_flip($this->steps);
    if (array_key_exists($stepText, $flip)) {
      $key = $flip[$stepText];
      $this->defaultKey = $key;
    }else {
      throw new \OutOfRangeException("Invalid step text " . $stepText);
    }
    return $this;
  }

  public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text,
      Form::KEY_STEPS => $this->steps,
      Form::KEY_DEFAULT => $this->defaultKey
    ];
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\element;

// libform
use tokyo\pmmp\libform\{
  form\Form
};

/**
 * ToggleClass
 */
class Toggle extends Element {

  /** @var string */
  protected const ELEMENT_NAME = "toggle";

  /** @var bool */
  protected $defaultValue = false;

  public function __construct(string $text, bool $value = false) {
    parent::__construct($text);
    $this->defaultValue = $value;
  }

  public function setDefaultValue(bool $value): Toggle {
    $this->defaultValue = $value;
    return $this;
  }

  final public function format(): array {
    $data = [
      Form::KEY_TYPE => self::ELEMENT_NAME,
      Form::KEY_TEXT => $this->text,
      Form::KEY_DEFAULT => $this->defaultValue
    ];
    return $data;
  }
}
<?php
namespace tokyo\pmmp\libform;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;

class EventListener implements Listener {

  public function onReceive(DataPacketReceiveEvent $event) {
    $pk = $event->getPacket();
    if ($pk instanceof ModalFormResponsePacket) {
      $player = $event->getPlayer();
      $formId = $pk->formId;
      $response = json_decode($pk->formData, true);
      if (($form = FormApi::getForm($formId)) !== null) {
        if (!$form->isRecipient($player)) {
          return false;
        }
        $callable = $form->getCallable();
        if ($callable !== null) {
          $callable($player, $response);
        }
        FormApi::removeForm($formId);
        $event->setCancelled();
      }
    }
  }

  public function onQuit(PlayerQuitEvent $event) {
    $player = $event->getPlayer();
    foreach (FormApi::getForms() as $formId => $form) {
      if ($form->isRecipient($player)) {
        FormApi::removeForm($formId);
        break;
      }
    }
  }
}<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\form;

// libform
use tokyo\pmmp\libform\{
  element\Element
};

/**
 * CustomForm
 */
class CustomForm extends Form implements \JsonSerializable {

  /** @var string */
  private const FORM_TYPE = "custom_form";
  /** @var array */
  protected $data = [
    Form::KEY_TYPE => self::FORM_TYPE,
    Form::KEY_TITLE => "",
    Form::KEY_CONTENT => []
  ];

  public function getElements(): array {
    return $this->data[Form::KEY_CONTENT];
  }

  public function getElement(int $key): ?Element {
    if (array_key_exists($key, $this->data[Form::KEY_CONTENT])) {
      return $this->data[Form::KEY_CONTENT][$key];
    }
    return null;
  }

  public function addElement(Element $element): CustomForm {
    if (!($element instanceof Button)) {// Button is for a ListForm
      $this->data[Form::KEY_CONTENT][] = $element;
    }
    return $this;
  }

  final public function jsonSerialize(): array {
    $data = $this->data;
    unset($data[Form::KEY_CONTENT]);
    foreach ($this->getElements() as $element) {
      $data[Form::KEY_CONTENT][] = $element->format();
    }
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\form;

// pocketmine
use pocketmine\{
  Player,
  network\mcpe\protocol\ModalFormRequestPacket
};

/**
 * abstractFormClass
 */
abstract class Form implements \JsonSerializable {

  /** @var string */
  public const KEY_TYPE = "type";
  public const KEY_CONTENT = "content";
  public const KEY_DATA = "data";
  public const KEY_IMAGE = "image";
  public const KEY_TITLE = "title";
  public const KEY_TEXT = "text";
  public const KEY_OPTIONS = "options";
  public const KEY_DEFAULT = "default";
  public const KEY_PLACEHOLDER = "placeholder";
  public const KEY_STEP = "step";
  public const KEY_STEPS = "steps";
  public const KEY_BUTTON1 = "button1";
  public const KEY_BUTTON2 = "button2";
  public const KEY_BUTTONS = "buttons";
  public const KEY_MIN = "min";
  public const KEY_MAX = "max";

  /** @var int */
  protected $id = 0;
  /** @var ?callable */
  private $callable = null;
  /** @var array */
  protected $data = [];
  /** @var string */
  protected $playerName = "";

  public function __construct(int $id, callable $callable = null) {
    $this->id = $id;
    $this->callable = $callable;
  }

  /**
   * @return int
   */
  public function getId(): int {
    return $this->id;
  }

  /**
   * @param  int $id
   * @return Form
   */
  public function setId(int $id): Form {
    $this->id = $id;
    return $this;
  }

  /**
   * @return string
   */
  public function getTitle(): string {
    return $this->data[self::KEY_TITLE];
  }

  /**
   * @param  string $title
   * @return Form
   */
  public function setTitle(string $title): Form {
    $this->data[self::KEY_TITLE] = $title;
    return $this;
  }

  /**
   * @return ?callable
   */
  public function getCallable(): ?callable {
    return $this->callable;
  }

  /**
   * @param  Player $player
   * @return bool
   */
  public function isRecipient(Player $player): bool {
    return $player->getName() === $this->playerName;
  }

  /**
   * @param Player $player
   * @return Form
   */
  public function sendToPlayer(Player $player): Form {
    $pk = new ModalFormRequestPacket;
    $pk->formId = $this->id;
    $pk->formData = json_encode($this);
    $this->playerName = $player->getName();
    $player->dataPacket($pk);
    return $this;
  }

  /**
   * @return array
   */
  abstract public function jsonSerialize(): array;
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\form;

// libform
use tokyo\pmmp\libform\{
  element\Button
};

/**
 * ListFormClass
 */
class ListForm extends Form implements \JsonSerializable {

  /** @var string */
  private const FORM_TYPE = "form";
  /** @var array */
  protected $data = [
    Form::KEY_TYPE => self::FORM_TYPE,
    Form::KEY_TITLE => "",
    Form::KEY_CONTENT => "",
    Form::KEY_BUTTONS => []
  ];

  public function getContent(): string {
    return $this->data[Form::KEY_CONTENT];
  }

  public function setContent(string $content): ListForm {
    $this->data[Form::KEY_CONTENT] = $content;
    return $this;
  }

  public function getButtons(): array {
    return $this->data[Form::KEY_BUTTONS];
  }

  public function addButton(Button $button): ListForm {
    $this->data[Form::KEY_BUTTONS][] = $button;
    return $this;
  }

  final public function jsonSerialize(): array {
    $data = $this->data;
    if (!empty(($buttons = $this->getButtons()))) {
      unset($data[Form::KEY_BUTTONS]);
      foreach ($this->getButtons() as $button) {
        $data[Form::KEY_BUTTONS][] = $button->format();
      }
    }
    return $data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform\form;

/**
 * ModalFormClass
 */
class ModalForm extends Form implements \JsonSerializable {

  /** @var string */
  private const FORM_TYPE = "modal";
  /** @var array */
  protected $data = [
    Form::KEY_TYPE => self::FORM_TYPE,
    Form::KEY_TITLE => "",
    Form::KEY_CONTENT => "",
    Form::KEY_BUTTON1 => "",
    Form::KEY_BUTTON2 => ""
  ];

  public function setButtonText(bool $button, string $text): ModalForm {
    if ($button) {
      $this->data[Form::KEY_BUTTON1] = $text;
    }else {
      $this->data[Form::KEY_BUTTON2] = $text;
    }
    return $this;
  }

  public function getContent(): string {
    return $this->data[Form::KEY_CONTENT];
  }

  public function setContent(string $content): ModalForm {
    $this->data[Form::KEY_CONTENT] = $content;
    return $this;
  }

  final public function jsonSerialize(): array {
    return $this->data;
  }
}
<?php

/**
 * // English
 *
 * libform is a library for PocketMine-MP for easy operation of forms
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * This software is distributed under "MIT license".
 * You should have received a copy of the MIT license
 * along with this program.  If not, see
 * < https://opensource.org/licenses/mit-license >.
 *
 * ---------------------------------------------------------------------
 * // æ—¥æœ¬èªž
 *
 * libformã¯ã€ãƒ•ã‚©ãƒ¼ãƒ ã‚’ç°¡å˜ã«æ“ä½œã™ã‚‹ãŸã‚ã®pocketmine-MPå‘ã‘ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã§ã™
 * Copyright (c) 2018 yuko fuyutsuki < https://github.com/fuyutsuki >
 *
 * ã“ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¯"MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹"ä¸‹ã§é…å¸ƒã•ã‚Œã¦ã„ã¾ã™ã€‚
 * ã‚ãªãŸã¯ã“ã®ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã¨å…±ã«MITãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ã‚³ãƒ”ãƒ¼ã‚’å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚
 * å—ã‘å–ã£ã¦ã„ãªã„å ´åˆã€ä¸‹è¨˜ã®URLã‹ã‚‰ã”è¦§ãã ã•ã„ã€‚
 * < https://opensource.org/licenses/mit-license >
 */

namespace tokyo\pmmp\libform;

// pocketmine
use pocketmine\plugin\PluginBase;
use pocketmine\Server;

// libform
use tokyo\pmmp\libform\form\CustomForm;
use tokyo\pmmp\libform\form\Form;
use tokyo\pmmp\libform\form\ListForm;
use tokyo\pmmp\libform\form\ModalForm;

/**
 * FormApiClass
 */
class FormApi {

  /** @var bool */
  private static $activated = false;
  /** @var Form[] */
  private static $forms = [];

  private function __construct() {
    // DONT USE THIS METHOD!
  }

  /**
   * @param PluginBase $plugin
   */
  public static function register(PluginBase $plugin): void {
    if (!self::$activated) {
      Server::getInstance()
        ->getPluginManager()
        ->registerEvents(new EventListener, $plugin);
    }
  }

  /**
   * Generate a custom form
   * @param  callable   $callable
   * @return CustomForm
   */
  public static function makeCustomForm(callable $callable = null): CustomForm {
    $formId = self::makeRandomFormId();
    $form = new CustomForm($formId, $callable);
    if ($callable !== null) self::$forms[$formId] = $form;
    return $form;
  }

  /**
   * Generate a list form
   * @param  callable $callable
   * @return ListForm
   */
  public static function makeListForm(callable $callable = null): ListForm {
    $formId = self::makeRandomFormId();
    $form = new ListForm($formId, $callable);
    if ($callable !== null) self::$forms[$formId] = $form;
    return $form;
  }

  /**
   * Generate a modal form
   * @param  callable  $callable
   * @return ModalForm
   */
  public static function makeModalForm(callable $callable = null): ModalForm {
    $formId = self::makeRandomFormId();
    $form = new ModalForm($formId, $callable);
    if ($callable !== null) self::$forms[$formId] = $form;
    return $form;
  }

  /**
   * Generate random formId
   * @return int formId
   */
  public static function makeRandomFormId(): int {
    return mt_rand(0, mt_getrandmax());
  }

  /**
   * @return array
   */
  public static function getForms(): array {
    return self::$forms;
  }

  /**
   * @param int $formId
   * @return Form|null
   */
  public static function getForm(int $formId): ?Form {
    if (array_key_exists($formId, self::$forms)) {
      return self::$forms[$formId];
    }else {
      return null;
    }
  }

  /**
   * @param int $formId
   */
  public static function removeForm(int $formId): void {
    if (array_key_exists($formId, self::$forms)) {
      unset(self::$forms[$formId]);
    }
  }

  /**
   * Check if the form has been canceled
   * @param  mixed $response
   * @return bool
   */
  public static function formCancelled($response): bool {
    return $response === null? true : false;
  }
}
Ì’õˆ¸¸Á-þ\=ÕKÑÇ]   GBMB