
<?php
echo "PocketMine-MP plugin if v3.2.0
This file has been generated using DevTools v1.13.2 at Wed, 17 Jul 2019 00:21:43 +0930
----------------
";

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(); ?>
E  e             a:9:{s:4:"name";s:2:"if";s:7:"version";s:5:"3.2.0";s:4:"main";s:17:"aieuo\ip\ifPlugin";s:3:"api";a:2:{i:0;s:5:"3.0.0";i:1;s:5:"4.0.0";}s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1563288703;}
   plugin.ymlA  ä-]A  tÞæ"¶      	   README.mdF  ä-]F  dU³¶      #   src/aieuo/ip/commands/ifCommand.php¯  ä-]¯  žÚb”¶      &   src/aieuo/ip/conditions/CanAddItem.php
  ä-]
  Ì-g¶      &   src/aieuo/ip/conditions/Comparison.php(  ä-](  ›¾¿Ä¶      %   src/aieuo/ip/conditions/Condition.phpŸ  ä-]Ÿ  k­¸>¶      ,   src/aieuo/ip/conditions/ConditionFactory.php{  ä-]{  ¨åeÿ¶      (   src/aieuo/ip/conditions/ConditionIds.phpö  ä-]ö  ø	Ï¶      &   src/aieuo/ip/conditions/ExistsItem.phpï  ä-]ï  M:‰ƒ¶      *   src/aieuo/ip/conditions/ExistsVariable.php†  ä-]†  ¬g¶      $   src/aieuo/ip/conditions/GameMode.php”	  ä-]”	  v0:¶      "   src/aieuo/ip/conditions/InArea.php÷  ä-]÷  !ÇP¶      "   src/aieuo/ip/conditions/InHand.php£  ä-]£  }¹:Ë¶      $   src/aieuo/ip/conditions/IsFlying.phpÙ  ä-]Ù  B¥ö¶          src/aieuo/ip/conditions/IsOp.php¦  ä-]¦  ZÚ,š¶      &   src/aieuo/ip/conditions/IsSneaking.phpú  ä-]ú  Ã¤¶      %   src/aieuo/ip/conditions/LessMoney.php}  ä-]}  1F¶      #   src/aieuo/ip/conditions/NoCheck.phpY  ä-]Y  0„¨—¶      %   src/aieuo/ip/conditions/OverMoney.php„  ä-]„  Lø"¶      (   src/aieuo/ip/conditions/RandomNumber.php  ä-]  ‘0 B¶      &   src/aieuo/ip/conditions/RemoveItem.php»
  ä-]»
  ÍŽÐ¶      %   src/aieuo/ip/conditions/TakeMoney.phpÒ  ä-]Ò  ß"¶      $   src/aieuo/ip/conditions/TypeItem.php‘  ä-]‘  {'©¶      %   src/aieuo/ip/conditions/TypeMoney.php5  ä-]5  '_V¿¶      )   src/aieuo/ip/economy/EconomyAPILoader.phpc  ä-]c  ™ªƒõ¶      &   src/aieuo/ip/economy/EconomyLoader.phpš  ä-]š  2'G¶      *   src/aieuo/ip/economy/MoneySystemLoader.phpm  ä-]m  ø]©¤¶      *   src/aieuo/ip/economy/PocketMoneyLoader.phpÄ  ä-]Ä  hßb†¶         src/aieuo/ip/EventListener.phpú&  ä-]ú&  %¹ŸI¶         src/aieuo/ip/form/BlockForm.phpm  ä-]m   °Þ¶      !   src/aieuo/ip/form/ChainIfForm.phpy  ä-]y  ³Ì5¶      !   src/aieuo/ip/form/CommandForm.phpg$  ä-]g$  kGp ¶         src/aieuo/ip/form/Elements.phpï  ä-]ï  „Æ¥7¶         src/aieuo/ip/form/EventForm.php†  ä-]†  ;ÌÓD¶          src/aieuo/ip/form/ExportForm.phpZ	  ä-]Z	  —~¶         src/aieuo/ip/form/Form.phpkN  ä-]kN  -3ê¶          src/aieuo/ip/form/ImportForm.phpq  ä-]q  ¼ÜC¶         src/aieuo/ip/ifAPI.php´  ä-]´  €!¶         src/aieuo/ip/ifPlugin.phpÆ  ä-]Æ  °M‹ß¶      %   src/aieuo/ip/manager/BlockManager.php+  ä-]+  ,L¶      '   src/aieuo/ip/manager/ChainIfManager.php_  ä-]_  ?ü¶      '   src/aieuo/ip/manager/CommandManager.phpï  ä-]ï  >G¶      %   src/aieuo/ip/manager/EventManager.php  ä-]  g@¶      "   src/aieuo/ip/manager/ifManager.php«  ä-]«  ˆ“$Ô¶      $   src/aieuo/ip/processes/AddEffect.phpl  ä-]l  [JÓi¶      )   src/aieuo/ip/processes/AddEnchantment.php¤  ä-]¤  Y8_¶      "   src/aieuo/ip/processes/AddItem.php¶  ä-]¶  ÝÛå²¶      #   src/aieuo/ip/processes/AddMoney.php  ä-]  ©t&¶      &   src/aieuo/ip/processes/AddVariable.phpÿ  ä-]ÿ  ‚K”¶      !   src/aieuo/ip/processes/Attack.php	  ä-]	  Åûv¶      +   src/aieuo/ip/processes/BroadcastMessage.phpi  ä-]i  ŒSyu¶      &   src/aieuo/ip/processes/Calculation.phpó  ä-]ó  ÉnÁ¶      "   src/aieuo/ip/processes/Command.phpJ  ä-]J  ¡ÏW¶      )   src/aieuo/ip/processes/CommandConsole.php¶  ä-]¶  nóÐN¶      &   src/aieuo/ip/processes/Cooperation.phpÕ  ä-]Õ   r5Ú¶      ,   src/aieuo/ip/processes/CooperationRepeat.phpO  ä-]O  ë®œ¶      )   src/aieuo/ip/processes/DelayedCommand.phpB  ä-]B  ÏzþÓ¶      )   src/aieuo/ip/processes/DeleteVariable.php„  ä-]„  ÜXt)¶      $   src/aieuo/ip/processes/DoNothing.php  ä-]  É¥®Ü¶      &   src/aieuo/ip/processes/EventCancel.phpÔ  ä-]Ô  ™`WÖ¶      -   src/aieuo/ip/processes/ExecuteOtherPlayer.phpO  ä-]O  ¥›¶         src/aieuo/ip/processes/Kick.php¦  ä-]¦  .
†e¶      !   src/aieuo/ip/processes/Motion.php
  ä-]
  ²‚÷Í¶      "   src/aieuo/ip/processes/Process.phpå  ä-]å  2ZX°¶      )   src/aieuo/ip/processes/ProcessFactory.php½  ä-]½  Ø)Þ¶      %   src/aieuo/ip/processes/ProcessIds.phpÿ  ä-]ÿ  Jëÿ¶      %   src/aieuo/ip/processes/RemoveItem.phpá
  ä-]á
   _æA¶      $   src/aieuo/ip/processes/SaveDatas.php­  ä-]­  Ü)¶      &   src/aieuo/ip/processes/SendMessage.phpP  ä-]P  Òg?¶      *   src/aieuo/ip/processes/SendMessageToOp.phpÒ  ä-]Ò  ]a8Ù¶      "   src/aieuo/ip/processes/SendTip.php)  ä-])  †œ”¶      $   src/aieuo/ip/processes/SendTitle.phpK  ä-]K  'ž¶      +   src/aieuo/ip/processes/SendVoiceMessage.phpÇ  ä-]Ç  fŒ{¶      $   src/aieuo/ip/processes/SetBlocks.phpê  ä-]ê  ÉwŠy¶      &   src/aieuo/ip/processes/SetGamemode.phpg	  ä-]g	  G¤†º¶      $   src/aieuo/ip/processes/SetHealth.php   ä-]   ,Õé1¶      &   src/aieuo/ip/processes/SetImmobile.php  ä-]  {¼Ò7¶      "   src/aieuo/ip/processes/SetItem.php  ä-]  ¨Ä—@¶      '   src/aieuo/ip/processes/SetMaxHealth.php1  ä-]1  í$¦Ï¶      %   src/aieuo/ip/processes/SetNametag.php:  ä-]:  ¥Èµ®¶      #   src/aieuo/ip/processes/SetScale.php	  ä-]	  Ã@ R¶      %   src/aieuo/ip/processes/SetSitting.php  ä-]  21`¨¶      &   src/aieuo/ip/processes/SetSleeping.phpö  ä-]ö  ŠÞM¿¶      $   src/aieuo/ip/processes/TakeMoney.php	  ä-]	  ´I€‘¶      #   src/aieuo/ip/processes/Teleport.php  ä-]  ~ñ_¶      &   src/aieuo/ip/processes/TypeCommand.phpý  ä-]ý  	Ü{ä¶      #   src/aieuo/ip/processes/TypeItem.phpØ	  ä-]Ø	  Cö+¶      &   src/aieuo/ip/processes/TypeMessage.php‰  ä-]‰  )/_\¶      $   src/aieuo/ip/processes/TypeMoney.php²  ä-]²  ºÅÞ¶      '   src/aieuo/ip/processes/TypePosition.phpu  ä-]u  &ÞE¶      (   src/aieuo/ip/processes/UnSetImmobile.php  ä-]  ö)ç€¶         src/aieuo/ip/Session.php€  ä-]€  >7Ày¶      (   src/aieuo/ip/task/DelayedCommandTask.phpm  ä-]m  Žuà¶         src/aieuo/ip/task/KickTask.php8  ä-]8  ŽeŠF¶         src/aieuo/ip/task/SaveTask.phpí  ä-]í  7È{o¶         src/aieuo/ip/utils/Messages.phpx  ä-]x  ¹ýÊ¶      &   src/aieuo/ip/variable/ListVariable.php  ä-]  ÅðÙ¶      (   src/aieuo/ip/variable/NumberVariable.php|  ä-]|  [³‰™¶      (   src/aieuo/ip/variable/StringVariable.php	  ä-]	  šŒ¢-¶      "   src/aieuo/ip/variable/Variable.php  ä-]  ‘%›1¶      (   src/aieuo/ip/variable/VariableHelper.phpg  ä-]g  kR­Í¶      ---
name: if
main: aieuo\ip\ifPlugin
version: 3.2.0
api:
- 3.0.0
- 4.0.0
load: POSTWORLD
author: aieuo
permissions:
  ifplugin.customcommand.op:
    default: op
    description: "ifplugin.customcommand.op"
  ifplugin.customcommand.true:
    default: true
    description: "ifplugin.customcommand.true"
...# if_plugin
https://forum.mcbe.jp/resources/172/

# TODO
- [ ] IFã‚’ã¾ã¨ã‚ã¦å‡ºåŠ›ã§ãã‚‹ã‚ˆã†ã«ã™ã‚‹  
- [x] å‡¦ç†ã¨ã‹è¿½åŠ ã™ã‚‹ã¨ãã«æ¤œç´¢ã§ãã‚‹ã‚ˆã†ã«ã™ã‚‹  
- [x] å¤‰æ•°ã«åž‹ã‚’è¿½åŠ ã™ã‚‹  
- [ ] å€¤ã‚’æ¯”è¼ƒã™ã‚‹ ã®åž‹ã‚’åŽ³ã—ãã™ã‚‹  
- [x] è¨ˆç®—ã™ã‚‹ ã®åž‹ã‚’åŽ³ã—ãã™ã‚‹
<?php

namespace aieuo\ip\commands;

use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;

use aieuo\ip\ifAPI;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;
use aieuo\ip\Session;

class ifCommand extends PluginCommand implements CommandExecutor {

	public function __construct($owner) {
		parent::__construct('if', $owner);
		$this->setPermission('op');
		$this->setDescription("æ¡ä»¶ã«ã‚ã£ãŸæ™‚ã€ã‚¤ãƒ™ãƒ³ãƒˆãŒèµ·ããŸæ™‚ã«ä½•ã‹ã‚’ã™ã‚‹");
		$this->setUsage("if <block | command | event>");
		$this->setExecutor($this);
		$this->owner = $owner;
		$this->form = new Form();
	}

	public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool {
		if(!$sender->isOp() or $sender->getName() === "CONSOLE") return true;
		$name = $sender->getName();
		if(!isset($args[0])){
			$form = $this->form->getSelectIfTypeForm();
			Form::sendForm($sender, $form, $this->form, "onSelectIfType");
			return true;
		}
		switch ($args[0]) {
			case 'block':
				if(isset($args[1])){
					$session = ifAPI::getSession($sender);
				switch ($args[1]) {
					case "edit":
						$sender->sendMessage("ç·¨é›†ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
						break;
					case "check":
						$sender->sendMessage("ç¢ºèªã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
						break;
					case "del":
						$sender->sendMessage("å‰Šé™¤ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
						break;
					case "copy":
						$sender->sendMessage("ã‚³ãƒ”ãƒ¼ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
						break;
					case "cancel":
						$session->setValid(false);
						$sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
						return true;
					}
					$session->setData("action", $args[1]);
					$session->setIfType(Session::BLOCK);
					$session->setValid();
						return true;
				}
                $form = $this->form->getBlockForm()->getSelectActionForm();
                Form::sendForm($sender, $form, $this->form->getBlockForm(), "onSelectAction");
				break;
			case 'command':
				if(isset($args[1])){
					$session = ifAPI::getSession($sender);
					$session->setValid();
					$session->setIfType(Session::COMMAND);
					$manager = $this->owner->getCommandManager();
					switch ($args[1]) {
						case "add":
						case "add_empty":
							$session->setData("action", $args[1]);
			                $form = $this->form->getCommandForm()->getAddCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onAddCommand");
							return true;
						case "edit":
							$session->setData("action", "edit");
							if(isset($args[2])){
								if(!$manager->isAdded($args[2])) {
									$sender->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
									$session->setValid(false);
									return true;
								}
		        				$session->setData("if_key", $args[2]);
								$datas = $manager->get($args[2]);
								$mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
					            $form = $this->form->getCommandForm()->getEditIfForm($mes);
					            Form::sendForm($sender, $form, $this->form->getCommandForm(), "onEditIf");
								return true;
							}
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
							return true;
						case "check":
							$session->setData("action", "check");
							if(isset($args[2])){
								if(!$manager->isAdded($args[2])) {
									$sender->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
									$session->setValid(false);
									return true;
								}
								$datas = $manager->get($args[2]);
								$mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
								$sender->sendMessage($mes);
								$session->setValid(false);
								return true;
							}
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
							return true;
						case "del":
							$session->setData("action", "del");
							if(isset($args[2])){
								if(!$manager->isAdded($args[2])) {
									$sender->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
									$session->setValid(false);
									return true;
								}
        						$session->setData("if_key", $args[2]);
					            $form = $this->form->getConfirmDeleteForm();
					            Form::sendForm($sender, $form, $this->form, "onDeleteIf");
								return true;
							}
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
							return true;
						case "cancel":
							$session->setValid(false);
							$sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
							return true;
					}
				}
                $form = $this->form->getCommandForm()->getSelectActionForm();
                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectAction");
				break;
			case 'event':
				$form = $this->form->getEventForm()->getSelectEventForm();
				Form::sendForm($sender, $form, $this->form->getEventForm(), "onSelectEvent");
				break;
			case "chain":
				if(isset($args[1])) {
					$session = ifAPI::getSession($sender);
					switch ($args[1]) {
						case 'add':
			                $session->setData("action", "add");
			                $form = $this->form->getChainForm()->getAddChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onAddChainIf");
							break;
						case 'edit':
                			$session->setData("action", "edit");
			                $form = $this->form->getChainForm()->getEditChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onEditChainIf");
							break;
						case 'del':
                			$session->setData("action", "del");
			                $form = $this->form->getChainForm()->getEditChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onEditChainIf");
							break;
						case 'list':
			                $form = $this->form->getChainForm()->getChainIfListForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onChainIfList");
							break;
						default:
			                $form = $this->form->getChainForm()->getSelectActionForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onselectAction");
							break;
					}
			        $session->setIfType(Session::CHAIN);
			        $session->setValid();
					return true;
				}
                $form = $this->form->getChainForm()->getSelectActionForm();
                Form::sendForm($sender, $form, $this->form->getChainForm(), "onselectAction");
				return true;
			case "import":
                $form = $this->form->getImportForm()->getImportListForm();
                Form::sendForm($sender, $form, $this->form->getImportForm(), "onImportList");
                break;
			default:
				$data = $this->form->getSelectIfTypeForm();
				Form::sendForm($sender, $data, $this->form, "onSelectIfType");
				break;
		}
		return true;
	}
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class CanAddItem extends TypeItem {

	protected $id = self::CAN_ADD_ITEM;
	protected $name = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã§ãã‚‹ã‹";
	protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«idãŒÂ§7<id>Â§fã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§få€‹è¿½åŠ ã§ãã‚‹ã‚¹ãƒšãƒ¼ã‚¹ãŒã‚ã‚‹ãªã‚‰";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«(".$item->getId().":".$item->getDamage().")"."ã‚’".$item->getCount()."å€‹è¿½åŠ ã§ãã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		$item = $this->getItem();
		if(!($item instanceof Item)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return self::ERROR;
		}
        if($player->getInventory()->canAddItem($item)) return self::MATCHED;
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Comparison extends Condition {

    protected $id = self::COMPARISON;
    protected $name = "äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹";
    protected $description = "Â§7<value1>Â§rã¨Â§7<value2>Â§rãŒÂ§7<operator>Â§rãªã‚‰";

	const ERROR = -1;
	const EQUAL = 0;
	const NOT_EQUAL = 1;
	const GREATER = 2;
	const GREATER_EQUAL = 3;
	const LESS = 4;
	const LESS_EQUAL = 5;
	const CONTAINS = 6;
	const NOT_CONTAINS = 7;

	public function getMessage() {
		if($this->getValues() === false) return false;
		$value1 = $this->getValue1();
		$value2 = $this->getValue2();
        switch ($this->getOperator()){
            case self::EQUAL:
                $mes = $value1."ã¨".$value2."ãŒç­‰ã—ã„ãªã‚‰";
                break;
            case self::NOT_EQUAL:
                $mes = $value1."ã¨".$value2."ãŒç­‰ã—ããªã„ã‹ã‚‰";
                break;
            case self::GREATER:
                $mes = $value1."ã‚ˆã‚Š".$value2."ãŒå°ã•ã„ãªã‚‰";
                break;
            case self::LESS:
                $mes = $value1."ã‚ˆã‚Š".$value2."ãŒå¤§ãã„ãªã‚‰";
                break;
            case self::GREATER_EQUAL:
                $mes = $value1."ãŒ".$value2."ä»¥ä¸Šãªã‚‰";
                break;
            case self::LESS_EQUAL:
                $mes = $value1."ãŒ".$value2."ä»¥ä¸‹ãªã‚‰";
                break;
            case self::CONTAINS:
                $mes = $value1."ã®ä¸­ã«".$value2."ãŒå«ã¾ã‚Œã¦ã„ã‚‹ãªã‚‰";
                break;
            case self::NOT_CONTAINS:
                $mes = $value1."ã®ä¸­ã«".$value2."ãŒå«ã¾ã‚Œã¦ã„ãªã„ãªã‚‰";
                break;
            default:
                return false;
        }
        return $mes;
	}

	public function getValue1() {
		return $this->getValues()[0];
	}

	public function getValue2() {
		return $this->getValues()[1];
	}

	public function getOperator() {
		return $this->getValues()[2];
	}

	public function setNumbers($value1, $value2, int $ope) {
		$this->setValues([$value1, $value2, $ope]);
	}

	public function parse(string $numbers) {
        if(!preg_match("/(.+)\[ope:([0-9])\](.+)/", $numbers, $matches)) return false;
        $operator = (int)$matches[2];
        $value1 = trim(rtrim($matches[1]));
        if(is_numeric($value1)) $value1 = (int)$value1;
        $value2 = trim(rtrim($matches[3]));
        if(is_numeric($value2)) $value2 = (int)$value2;
        return [$value1, $value2, $operator];
	}

	public function check() {
		$player = $this->getPlayer();
		if($this->getValues() === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return self::ERROR;
		}
		$value1 = $this->getValue1();
		$value2 = $this->getValue2();
		$result = self::NOT_MATCHED;
        switch ($this->getOperator()){
            case self::EQUAL:
                if($value1 == $value2) $result = self::MATCHED;
                break;
            case self::NOT_EQUAL:
                if($value1 != $value2) $result = self::MATCHED;
                break;
            case self::GREATER:
                if($value1 > $value2) $result = self::MATCHED;
                break;
            case self::LESS:
                if($value1 < $value2) $result = self::MATCHED;
                break;
            case self::GREATER_EQUAL:
                if($value1 >= $value2) $result = self::MATCHED;
                break;
            case self::LESS_EQUAL:
                if($value1 <= $value2) $result = self::MATCHED;
                break;
            case self::CONTAINS:
                if(strpos($value1, $value2) !== false) $result = self::MATCHED;
                break;
            case self::NOT_CONTAINS:
                if(strpos($value1, $value2) === false) $result = self::MATCHED;
                break;
            default:
                $player->sendMessage("Â§c[äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§r");
                break;
        }
        return $result;
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$values = $this->parse($default);
		$value1 = $default;
		$operator = self::EQUAL;
		$value2 = "";
		if($values !== false) {
			$value1 = $values[0];
			$operator = $values[2];
			$value2 = $values[1];
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<value1>Â§f ä¸€ã¤ç›®ã®å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 100", $value1),
                Elements::getDropdown("\nÂ§7<operator>Â§f é¸ã‚“ã§ãã ã•ã„", [
                	"äºŒã¤ã®å€¤ãŒç­‰ã—ã„ (value1 == value2)",
                	"äºŒã¤ã®å€¤ãŒç­‰ã—ããªã„ (value1 != value2)",
                	"ä¸€ã¤ç›®ã®å€¤ãŒäºŒã¤ç›®ã®å€¤ã‚ˆã‚Šå¤§ãã„ (value1 > value2)",
                	"ä¸€ã¤ç›®ã®å€¤ãŒäºŒã¤ç›®ã®å€¤ã‚ˆã‚Šå°ã•ã„ (value1 < value2)",
                	"ä¸€ã¤ç›®ã®å€¤ãŒäºŒã¤ç›®ã®å€¤ä»¥ä¸Š (value1 >= value2)",
                	"ä¸€ã¤ç›®ã®å€¤ãŒäºŒã¤ç›®ã®å€¤ä»¥ä¸Š (value1 <= value2)",
                	"ä¸€ã¤ç›®ã®å€¤ã®ä¸­ã«äºŒã¤ç›®ã®å€¤ãŒå«ã¾ã‚Œã¦ã„ã‚‹ (value2 in value1)",
                	"ä¸€ã¤ç›®ã®å€¤ã®ä¸­ã«äºŒã¤ç›®ã®å€¤ãŒå«ã¾ã‚Œã¦ã„ãªã„ (value2 not in value1)",
                ], $operator),
                Elements::getInput("\nÂ§7<value2>Â§f äºŒã¤ç›®ã®å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 50", $value2),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "" or $datas[3] === "") {
    		$status = null;
    	} elseif($this->parse($datas[1]."[ope:".$datas[2]."]".$datas[3]) === false) {
    		$status = false;
    	}
    	return ["status" => $status, "contents" => $datas[1]."[ope:".$datas[2]."]".$datas[3], "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\Player;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Condition implements ConditionIds {

	const MATCHED = 0;
	const NOT_MATCHED = 1;
	const NOT_FOUND = 2;
	const ERROR = -1;

	/** @var Player */
	private $player;

	/** @var array */
	private $values = [];

	/** @var int */
	protected $id;

	/** @var string */
	protected $name = "";

	/** @var string */
	protected $description = "";

	public function __construct($player = null) {
		$this->player = $player;
	}

	public static function get($id) {
		return ConditionFactory::get($id);
	}

	public function getId() {
		return $this->id;
	}

	public function getName() {
		return $this->name;
	}

	public function getDescription() {
		return $this->description;
	}

	public function parse(string $str) {
		return $str;
	}

	public function setPlayer(Player $player) : self {
		$this->player = $player;
		return $this;
	}

	public function getPlayer() : Player {
		return $this->player;
	}

	public function setValues($values) : self {
		$this->values = $values;
		return $this;
	}

	public function getValues() {
		return $this->values;
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas){
    	return ["status" => true, "contents" => "", "delete" => $datas[1], "cancel" => $datas[2]];
    }

	public function check() {
		return Ifs::NOT_FOUND;
	}
}<?php

namespace aieuo\ip\conditions;

class ConditionFactory {
	private static $list = [];

	public static function init() {
		self::register(new NoCheck());
		self::register(new TakeMoney());
		self::register(new OverMoney());
		self::register(new LessMoney());
		self::register(new InHand());
		self::register(new ExistsItem());
		self::register(new RemoveItem());
		self::register(new CanAddItem());
		self::register(new IsOp());
		self::register(new IsSneaking());
		self::register(new IsFlying());
		self::register(new GameMode());
		self::register(new InArea());
		self::register(new RandomNumber());
		self::register(new Comparison());
		self::register(new ExistsVariable());
	}
	/**
	 * @param  int $id
	 * @return Condition | null
	 */
	public static function get($id) {
		if(isset(self::$list[$id])) {
			return clone self::$list[$id];
		}
		return new Condition();
	}

	public static function getAll() {
		return self::$list;
	}

	/**
	 * @param  Condition $condition
	 */
	public static function register(Condition $condition) {
		self::$list[$condition->getId()] = clone $condition;
	}
}<?php

namespace aieuo\ip\conditions;

interface ConditionIds {
    const TAKEMONEY = 0;
    const IN_HAND = 1;
    const EXISTS_ITEM = 2;
    const IS_SNEAKING = 3;
    const OVERMONEY = 4;
    const REMOVE_ITEM = 5;
    const GAMEMODE = 6;
    const NO_CHECK = 7;
    const COMPARISON = 8;
    const IS_OP = 9;
    const IS_FLYING = 10;
    const IN_AREA = 11;
    const RANDOM_NUMBER = 12;
    const EXISTS_VARIABLE = 13;
    const LESSMONEY = 14;
    const CAN_ADD_ITEM = 15;
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class ExistsItem extends TypeItem {

	protected $id = self::EXISTS_ITEM;
	protected $name = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ãŒå…¥ã£ã¦ã‚‹ã‹";
	protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«idãŒÂ§7<id>Â§fã®ã‚¢ã‚¤ãƒ†ãƒ ãŒÂ§7<count>Â§få€‹ä»¥ä¸Šã‚ã‚‹ãªã‚‰";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«(".$item->getId().":".$item->getDamage().")"."ãŒ".$item->getCount()."å€‹ã‚ã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		$item = $this->getItem();
		if(!($item instanceof Item)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return self::ERROR;
		}
        if($player->getInventory()->contains($item)) return self::MATCHED;
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class ExistsVariable extends Condition {

	protected $id = self::EXISTS_VARIABLE;
    protected $name = "å¤‰æ•°ãŒå­˜åœ¨ã™ã‚‹ã‹";
	protected $description = "å¤‰æ•°Â§7<variable>Â§fãŒå­˜åœ¨ã™ã‚‹ã‹";

	public function getMessage() {
		$name = $this->getVariableName();
		return $name."ã¨ã„ã†åå‰ã®å¤‰æ•°ãŒå­˜åœ¨ã™ã‚‹ãªã‚‰";
	}

	public function getVariableName() {
		return $this->getValues();
	}

	public function setVariableName(string $variable) {
		$this->setValues($variable);
	}

	public function check() {
		if(ifPlugin::getInstance()->getVariableHelper()->exists($this->getVariableName())) return self::MATCHED;
		return self::NOT_MATCHED;
	}


	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<variable>Â§f å¤‰æ•°ã®åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas){
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class GameMode extends Condition {

	protected $id = self::GAMEMODE;
    protected $name = "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒæŒ‡å®šã—ãŸã‚‚ã®ã ã£ãŸã‚‰";
    protected $description = "ãƒ—ãƒ¬ãƒ¼ãƒ¤ãƒ¼ã®ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒÂ§7<gamemode>Â§fã ã£ãŸã‚‰";

	public function getMessage() {
		$gamemode = $this->getGamemode();
		if($gamemode === false) return false;
		return "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒ".$gamemode."ãªã‚‰";
	}

	public function getGamemode() {
		return $this->getValues();
	}

	public function setGamemode(int $gamemode) {
		$this->setValues($gamemode);
	}

	public function parse(string $gamemode) {
		$intGamemode = Server::getInstance()->getGamemodeFromString($gamemode);
		if($intGamemode === -1) return false;
		return $intGamemode;
	}

	public function check() {
		$player = $this->getPlayer();
		$gamemode = $this->getGamemode();
		if($gamemode === false) {
			$player->sendMessage("Â§c[".$this->getName()."] ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
			return self::ERROR;
		}
        return $player->getGamemode() === $gamemode ? self::MATCHED : self::NOT_MATCHED;
	}


	public function getEditForm(string $default = "", string $mes = "") {
		if($default === "")
		{
			$gamemode = 0;
		}
		elseif(($gamemode = $this->parse($default)) === false)
		{
			$mes .= "Â§cã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“Â§f";
			$gamemode = 0;
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getDropdown("\nÂ§7<gamemode>Â§f ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’é¸æŠžã—ã¦ä¸‹ã•ã„", ["ã‚µãƒã‚¤ãƒãƒ«", "ã‚¯ãƒªã‚¨ã‚¤ãƒ†ã‚£ãƒ–", "ã‚¢ãƒ‰ãƒ™ãƒ³ãƒãƒ£ãƒ¼", "ã‚¹ãƒšã‚¯ãƒ†ã‚¤ã‚¿ãƒ¼"], $gamemode),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$gamemode = $this->parse((string)$datas[1]);
	    	if($gamemode === false) $status = false;
	    }
    	return ["status" => $status, "contents" => (string)$datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\math\Vector3;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class InArea extends Condition {

	protected $id = self::IN_AREA;
    protected $name = "æŒ‡å®šã—ãŸç¯„å›²å†…ã«ã„ãŸã‚‰";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒÂ§7<x|y|z>Â§rè»¸ãŒÂ§7<min>Â§rï½žÂ§7<max>Â§rã®ç¯„å›²ã«ã„ãŸã‚‰";

	public function __construct($player = null, $area = false) {
		parent::__construct($player);
		$this->setValues($area);
	}

	public function getMessage() {
		$areas = $this->getArea();
		if($areas === false) return false;
		$mes = [];
		foreach ($areas as $axis => $area) {
			$mes[] = $axis."è»¸ãŒ".$area[0]."~".$area[1]."ã®ç¯„å›²";
		}
		return implode(",", $mes)."ã«ã„ã‚‹ãªã‚‰";
	}

	public function getArea() {
		return $this->getValues();
	}

	public function setArea(Array $area) {
		$this->setValues($area);
	}

	public function parse(string $areas) {
        if(!preg_match("/([xyz]\(-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*\))+/", $areas, $matches)) return false;
        array_shift($matches);
        $areas = [];
        foreach ($matches as $match) {
            if(!preg_match("/([xyz])\((-?[0-9]+\.?[0-9]*),(-?[0-9]+\.?[0-9]*)\)/", $match, $matches1)) continue;
            $min = min((float)$matches1[2], (float)$matches1[3]);
            $max = max((float)$matches1[2], (float)$matches1[3]);
            $areas[$matches1[1]] = [$min, $max];
        }
        return $areas;
	}

	public function check() {
		$player = $this->getPlayer();
		$areas = $this->getArea();
		if($areas === false) {
			$player->sendMessage("Â§c[æŒ‡å®šã—ãŸç¯„å›²å†…ã«ã„ãŸã‚‰] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f");
			return self::ERROR;
		}
        foreach ($areas as $axis => $area) {
            if($player->$axis < $area[0] and $player->$axis > $area[1]) return self::NOT_MATCHED;
        }
        return self::MATCHED;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$areas = $this->parse($default);
		if($areas === false) {
			$areas = ["x" => $default, "y" => "", "z" => ""];
			if($default !== "") $mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}

		$content = [Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes))];
		foreach (["x", "y", "z"] as $axis) {
			if(!isset($areas[$axis])) $areas[$axis] = "";
			if(is_array(($areas[$axis]))) $areas[$axis] = implode(",", $areas[$axis]);
			$content[] = Elements::getInput("\nÂ§7<".$axis.">Â§f ".$axis."è»¸ã®ç¯„å›²ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„ (æŒ‡å®šã—ãªã„å ´åˆã¯ç©ºç™½ã§)", "ä¾‹) 0,100", $areas[$axis]);
		}
		$content[] = Elements::getToggle("å‰Šé™¤ã™ã‚‹");
		$content[] = Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => $content
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$area_str = $datas[1] !== "" ? "x(".$datas[1].")" : "";
    	$area_str .= $datas[2] !== "" ? "y(".$datas[2].")" : "";
    	$area_str .= $datas[3] !== "" ? "z(".$datas[3].")" : "";
    	if($datas[1] === "" and $datas[2] === "" and $datas[3] === "") {
    		$status = null;
    	} else {
	    	$areas = $this->parse($area_str);
	    	if($areas == false) $status = false;
	    }
    	return ["status" => $status, "contents" => $area_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class InHand extends TypeItem {

	protected $id = self::IN_HAND;
    protected $name = "æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ã‚’æ‰‹ã«æŒã£ã¦ã‚‹ã‹";
    protected $description = "idãŒÂ§7<id>Â§fã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§få€‹ä»¥ä¸Šæ‰‹ã«æŒã£ã¦ã„ã‚‹ãªã‚‰";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "æ‰‹ã«(".$item->getId().":".$item->getDamage().")"."ã‚’".$item->getCount()."ã‚’æŒã£ã¦ã„ã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
	    $item = $this->getItem();
	    if(!($item instanceof Item)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return self::ERROR;
		}
	    $hand = $player->getInventory()->getItemInHand();
        if(
        	$hand->getId() == $item->getId()
        	and $hand->getDamage() == $item->getDamage()
        	and $hand->getCount() >= $item->getCount()
        ) {
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

class IsFlying extends Condition {

	protected $id = self::IS_FLYING;
	protected $name = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒé£›ã‚“ã§ã„ã‚‹ã‹";
	protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒé£›ã‚“ã§ã„ã‚‹ãªã‚‰";

	public function getMessage() {
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒé£›ã‚“ã§ã„ã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isFlying() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

class IsOp extends Condition {

	protected $id = self::IS_OP;
	protected $name = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒopã‹";
	protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒopãªã‚‰";

	public function getMessage() {
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒopãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isOp() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

class IsSneaking extends Condition {

	protected $id = self::IS_SNEAKING;
	protected $name = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹ã‹";
	protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹ãªã‚‰";

	public function getMessage() {
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isSneaking() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class LessMoney extends TypeMoney {

	protected $id = self::LESSMONEY;
    protected $name = "æ‰€æŒé‡‘ãŒæŒ‡å®šã—ãŸé‡‘é¡ä»¥ä¸‹ã‹";
    protected $description = "æ‰€æŒé‡‘ãŒÂ§7<amount>Â§fä»¥ä¸‹ãªã‚‰";

	public function getMessage() {
		return "æ‰€æŒé‡‘ãŒ".$this->getAmount()."ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if($economy === null){
            $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if($mymoney <= $this->getAmount()) return self::MATCHED;
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

class NoCheck extends Condition {

	protected $id = self::NO_CHECK;
	protected $name = "ä½•ã‚‚ç¢ºèªã—ãªã„";
	protected $description = "ä½•ã‚‚ç¢ºèªã—ãªã„";

	public function getMessage() {
		return "ä½•ã‚‚ç¢ºèªã—ãªã„";
	}

	public function check() {
		return self::MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class OverMoney extends TypeMoney {

	protected $id = self::OVERMONEY;
    protected $name = "æ‰€æŒé‡‘ãŒæŒ‡å®šã—ãŸé‡‘é¡ä»¥ä¸Šã‹";
    protected $description = "æ‰€æŒé‡‘ãŒÂ§7<amount>Â§fä»¥ä¸Šãªã‚‰";

	public function getMessage() {
		return "æ‰€æŒé‡‘ãŒ".$this->getAmount()."ä»¥ä¸Šãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if($economy === null) {
            $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if($mymoney >= $this->getAmount()) return self::MATCHED;
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class RandomNumber extends Condition {

	protected $id = self::RANDOM_NUMBER;
    protected $name = "ä¹±æ•°ãŒæŒ‡å®šã—ãŸã‚‚ã®ã ã£ãŸã‚‰";
    protected $description = "Â§7<min>Â§rï½žÂ§7<max>Â§rã®ç¯„å›²ã§ç”Ÿæˆã—ãŸä¹±æ•°ãŒÂ§7<number>Â§7ã ã£ãŸã‚‰";

	public function getMessage() {
		if($this->getValues() === false) return false;
		return $this->getMin()."~".$this->getMax()."ã®ç¯„å›²ã®ä¹±æ•°ãŒ".$this->getCheck()."ãªã‚‰";
	}

	public function getMin() {
		return $this->getValues()[0];
	}

	public function getMax() {
		return $this->getValues()[1];
	}

	public function getCheck() {
		return $this->getValues()[2];
	}

	public function setNumbers(int $min, int $max, int $check) {
		$this->setValues([$min, $max, $check]);
	}

	public function parse(string $numbers) {
        if(!preg_match("/(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/", $numbers, $matches)) return false;
        $min = min((int)$matches[1], (int)$matches[2]);
        $max = max((int)$matches[1], (int)$matches[2]);
        return [$min, $max, (int)$matches[3]];
	}

	public function check() {
		$player = $this->getPlayer();
		if($this->getValues() === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f");
			return self::ERROR;
		}
        $rand = mt_rand($this->getMin(), $this->getMax());
        if($rand === $this->getCheck()) return self::MATCHED;
        return self::NOT_MATCHED;
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$numbers = $this->parse($default);
		$min = $default;
		$max = "";
		$check = "";
		if($numbers !== false) {
			$min = $numbers[0];
			$max = $numbers[1];
			$check = $numbers[2];
			if($check > $max or $check < $min) {
				$mes .= "Â§eæŒ‡å®šã—ãŸæ•°".$check."ã¯".$min."~".$max."ã®ç¯„å›²ã®ä¹±æ•°ã§ç”Ÿæˆã•ã‚Œã‚‹ã“ã¨ã¯ã‚ã‚Šã¾ã›ã‚“Â§f";
			}
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<min>Â§f ä¹±æ•°ã®ç¯„å›²ã®æœ€å°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1", $min),
                Elements::getInput("\nÂ§7<max>Â§f ä¹±æ•°ã®ç¯„å›²ã®æœ€å¤§å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $max),
                Elements::getInput("\nÂ§7<check>Â§f ç¢ºèªã™ã‚‹æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 3", $check),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$num_str = $datas[1].",".$datas[2].",".$datas[3];
    	if($datas[1] === "" or $datas[2] === "" or $datas[3] === "") {
    		$status = null;
    	} else {
	    	$num = $this->parse($num_str);
	    	if($num === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $num_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class RemoveItem extends TypeItem {

	protected $id = self::REMOVE_ITEM;
    protected $name = "æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ãŒã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚ã‚‹ãªã‚‰å‰Šé™¤ã™ã‚‹";
    protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰idãŒÂ§7<id>Â§fã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§få€‹å‰Šé™¤ã§ãã‚‹ãªã‚‰";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰(".$item->getId().":".$item->getDamage().")"."ã‚’".$item->getCount()."å€‹å‰Šé™¤ã§ãã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
		$item = $this->getItem();
	    if(!($item instanceof Item)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return self::ERROR;
		}
		if($item->getCount() === 0) {
            $count = 0;
            foreach ($player->getInventory()->getContents() as $item1) {
                if($item1->getId() == $item->getId() and $item1->getDamage() == $item->getDamage()) $count += $item1->getCount();
            }
            if($count == 0) return self::NOT_MATCHED;
            $item->setCount($count);
		}
        if($player->getInventory()->contains($item)) {
            $player->getInventory()->removeItem($item);
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			if($count === 0) $mes .= "Â§eæŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ã‚’ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰ã™ã¹ã¦å‰Šé™¤ã—ã¾ã™Â§f";
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“ (idã¯0ä»¥ä¸Šã®æ•°å­—ã§å…¥åŠ›ã—ã¦ãã ã•ã„)Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<id>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getInput("\nÂ§7<count>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(å…¨ã¦æ¶ˆã™å ´åˆã¯0ã‚’å…¥åŠ›ã™ã‚‹ã‹ç©ºç™½ã«ã—ã¦ãã ã•ã„)", "ä¾‹) 5", $count),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TakeMoney extends TypeMoney {

	protected $id = self::TAKEMONEY;
    protected $name = "ãŠé‡‘ã‚’æ¸›ã‚‰ã™";
    protected $description = "ãŠé‡‘ã‚’Â§7<amount>Â§fæ‰•ãˆã‚‹ãªã‚‰";

	public function getMessage() {
		return "ãŠé‡‘ã‚’".$this->getAmount()."æ‰•ãˆã‚‹ãªã‚‰";
	}

	public function check() {
		$player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if($economy === null) {
            $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if($mymoney >= $this->getAmount()){
            $economy->takeMoney($player->getName(), $this->getAmount());
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeItem extends Condition {
	public function getItem() {
		return $this->getValues();
	}

	public function setItem(Item $item) {
		$this->setValues($item);
	}

	public function parse(string $id) {
		if(!preg_match("/^\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*$/", $id, $ids)) return false;
		$item = Item::get((int)$ids[1], empty($ids[2]) ? 0 : (int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3]);
		return $item;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			if($count === 0) $mes .= "Â§eå€‹æ•°ãŒ0ã«ãªã£ã¦ã„ã¾ã™Â§f";
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“(idã¯æ•°å­—ã§0ä»¥ä¸Šã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„)Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<id>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getInput("\nÂ§7<count>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $count),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$id = explode(":", $datas[1]);
    	if(!isset($id[1])) $id[1] = 0;
    	$ids_str = $id[0].":".$id[1].":".$datas[2];
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$ids = $this->parse($ids_str);
	    	if($ids === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $ids_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeMoney extends Condition {
	public function __construct($player = null, $amount = 0) {
		parent::__construct($player);
		$this->setValues($amount);
	}

	public function getAmount() {
		return $this->getValues();
	}

	public function setAmount(int $amount) {
		$this->setValues($amount);
	}

	public function parse(string $amount) {
		$amount = (int)mb_convert_kana($amount, "n");
		return $amount;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$money = $this->parse($default);
		if($money <= 0) $money = $default;
		if($money <= 0 and $default !== "") $mes .= "Â§e1ä»¥ä¸Šã®æ•°å­—ã‚’å…¥åŠ›ã™ã‚‹ã“ã¨ã‚’æŽ¨å¥¨ã—ã¾ã™Â§f";
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)."\n"),
                Elements::getInput("\nÂ§7<amount>Â§f å€¤æ®µã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1000", $money),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\economy;

class EconomyAPILoader implements EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney(string $name){
		return (int)$this->getPlugin()->mymoney($name);
	}

	public function addMoney(string $name, int $money){
        $this->getPlugin()->addMoney($name, $money);
		return true;
	}

	public function takeMoney(string $name, int $money){
        $this->getPlugin()->reduceMoney($name, $money);
		return true;
	}
}<?php

namespace aieuo\ip\economy;

interface EconomyLoader {
    /**
     * æ‰€æŒé‡‘ã‚’å–å¾—ã™ã‚‹
     * @param  string $name ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®åå‰
     * @return int          æ‰€æŒé‡‘
     */
    public function getMoney(string $name);

    /**
     * æ‰€æŒé‡‘ã‚’å¢—ã‚„ã™
     * @param string $name  ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®åå‰
     * @param int    $money å¢—ã‚„ã™é¡
     */
    public function addMoney(string $name, int $money);

    /**
     * æ‰€æŒé‡‘ã‚’æ¸›ã‚‰ã™
     * @param  string $name  ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®åå‰
     * @param  int    $money æ¸›ã‚‰ã™é¡
     */
    public function takeMoney(string $name, int $money);
}<?php

namespace aieuo\ip\economy;

class MoneySystemLoader implements EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney(string $name){
		return (int)$this->getPlugin()->getAPI()->get($name);
	}

	public function addMoney(string $name, int $money){
		$this->getPlugin()->getAPI()->increase($name, $money);
		return true;
	}

	public function takeMoney(string $name, int $money){
		$this->getPlugin()->getAPI()->reduce($name, $money);
		return true;
	}
}<?php

namespace aieuo\ip\economy;

class PocketMoneyLoader implements EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney(string $name){
		return (int)$this->getPlugin()->getMoney($name);
	}

	public function addMoney(string $name, int $money){
		$mymoney = $this->getMoney($name);
        $this->getPlugin()->setMoney($name, $mymoney + $money);
		return true;
	}

	public function takeMoney(string $name, int $money){
		$mymoney = $this->getMoney($name);
        $this->getPlugin()->setMoney($name, $mymoney - $money);
		return true;
	}
}<?php

namespace aieuo\ip;

use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\Player;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerToggleFlightEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\inventory\CraftItemEvent;

use aieuo\ip\ifAPI;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;
use aieuo\ip\Session;

class EventListener implements Listener {
	public function __construct($owner){
		$this->owner = $owner;
	}

    public function getOwner(){
        return $this->owner;
    }
    public function chat(PlayerChatEvent $event){
        $this->onEvent($event, "PlayerChatEvent");
    }
    public function commandProcess(PlayerCommandPreprocessEvent $event){
        $this->onEvent($event, "PlayerCommandPreprocessEvent");

        if($event->isCancelled()) return;
        $cmd = mb_substr($event->getMessage(), 1);
        $manager = $this->getOwner()->getCommandManager();
        if($manager->isAdded($cmd)){
            if($manager->isSubCommand($cmd) and !$manager->isAdded($cmd)) {
                $event->getPlayer()->sendMessage("Usage: /".$manager->getOriginCommand($cmd)." <".implode(" | ", $manager->getSubcommands($cmd)).">");
                return;
        }
            $datas = $manager->get($cmd);
            if($datas["permission"] == "ifplugin.customcommand.op" and !$event->getPlayer()->isOp()) return;
            $manager->executeIfMatchCondition($event->getPlayer(),
                $datas["if"],
                $datas["match"],
                $datas["else"],
                [
                    "player" => $event->getPlayer(),
                    "command" => $cmd,
                    "event" => $event
                ]
            );
        }
    }
    public function join(PlayerJoinEvent $event){
        $this->onEvent($event, "PlayerJoinEvent");
    }
    public function craft(CraftItemEvent $event){
        $this->onEvent($event, "CraftItemEvent");
    }
    public function quit(PlayerQuitEvent $event){
        $this->onEvent($event, "PlayerQuitEvent");
    }
    public function toggleFlight(PlayerToggleFlightEvent $event){
        $this->onEvent($event, "PlayerToggleFlightEvent");
    }
    public function blockBreak(BlockBreakEvent $event){
        $this->onEvent($event, "BlockBreakEvent");
    }
    public function blockPlace(BlockPlaceEvent $event){
        $this->onEvent($event, "BlockPlaceEvent");
    }
    public function entityDamage(EntityDamageEvent $event){
        $this->onEvent($event, "EntityDamageEvent");
    }
    public function entityDamageByEntity(EntityDamageByEntityEvent $event){
        $this->onEvent($event, "EntityAttackEvent");
    }
    public function entityDeath(EntityDeathEvent $event){
        $this->onEvent($event, "EntityDeathEvent");
    }
    public function entityLevelChange(EntityLevelChangeEvent $event){
        $this->onEvent($event, "EntityLevelChangeEvent");
    }
    public function dataPacketSend(DataPacketSendEvent $event){
        $pk = $event->getPacket();
        if($pk instanceof TextPacket and $pk->type === TextPacket::TYPE_RAW) {
            $this->onEvent($event, "TextPacketSendEvent");
        }
    }
    public function onEvent($event, $eventname){
        switch ($eventname) {
            case 'CraftItemEvent':
            case 'PlayerInteractEvent':
            case 'PlayerChatEvent':
            case 'PlayerCommandPreprocessEvent':
            case 'PlayerJoinEvent':
            case 'PlayerQuitEvent':
            case 'PlayerToggleFlightEvent':
            case 'BlockBreakEvent':
            case 'BlockPlaceEvent':
            case 'TextPacketSendEvent':
                $player = $event->getPlayer();
                break;
            case 'EntityDamageEvent':
            case 'EntityDeathEvent':
            case 'EntityLevelChangeEvent':
                $player = $event->getEntity();
                if(!($player instanceof Player)) return;
                break;
            case "EntityAttackEvent":
                $player = $event->getDamager();
                if(!($player instanceof Player)) return;
                break;
        }
        $manager = $this->getOwner()->getEventManager();
        $datas = $manager->getFromEvent($eventname);
        foreach ($datas as $key => $data) {
            $data = $manager->get($key, ["eventname" => $eventname]);
            $manager->executeIfMatchCondition($player,
                $data["if"],
                $data["match"],
                $data["else"],
                [
                    "player" => $player,
                    "eventname" => $eventname,
                    "event" => $event
                ]
            );
        }
    }

	public function interact(PlayerInteractEvent $event){
        $player = $event->getPlayer();
        if(!isset($this->touch[$player->getName()])) $this->touch[$player->getName()] = 0;
        $tick = Server::getInstance()->getTick();
        if($tick - $this->touch[$player->getName()] <= 3) {
            return;
        }
        $this->touch[$player->getName()] = $tick;
		$this->onEvent($event, "PlayerInteractEvent");

        $manager = $this->getOwner()->getBlockManager();
        $block = $event->getBlock();
        $pos = $manager->getPosition($block);
		if($player->isOp()){
			if(($session = ifAPI::getSession($player))->isValid()){
				$type = $session->getData("action");
				$manager = $this->getOwner()->getBlockManager();
				switch ($type) {
					case 'edit':
                        $session->setData("if_key", $pos);
                        if($manager->isAdded($pos)) {
                            $datas = $manager->get($pos);
                        } else {
                            $datas = $manager->repairIF([]);
                            $manager->set($pos);
                        }
                        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                        $form = (new Form)->getEditIfForm($mes);
                        Form::sendForm($player, $form, new Form(), "onEditIf");
						return;
					case 'check':
	                    $pos = $manager->getPosition($block);
	                    if(!$manager->isAdded($pos)){
	                        $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
	                        return;
	                    }
	                    $datas = $manager->get($pos);
	                    $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
	                    $player->sendMessage($mes);
						break;
                    case 'copy':
                        $pos = $manager->getPosition($block);
                        if(!$manager->isAdded($pos)){
                            $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
                            return;
                        }
                        $session->setData("if_key", $pos);
                        $session->setData("action", "paste");
                        $player->sendMessage("è²¼ã‚Šä»˜ã‘ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                        return;
                    case 'paste':
                        $pos = $manager->getPosition($block);
                        if($manager->isAdded($pos)){
                            $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯ã™ã§ã«è¿½åŠ ã•ã‚Œã¦ã„ã¾ã™");
                            return;
                        }
                        $manager->set($pos, $manager->get($session->getData("if_key")));
                        $player->sendMessage("è²¼ã‚Šä»˜ã‘ã¾ã—ãŸ");
                        break;
					case 'del':
	                    $pos = $manager->getPosition($block);
	                    if(!$manager->isAdded($pos)){
	                        $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
	                        return;
	                    }
                        $form = (new Form())->getConfirmDeleteForm();
                        Form::sendForm($player, $form, new Form(), "onDeleteIf");
						break;
				}
				$session->setValid(false);
                return;
			}
		}
        if($manager->isAdded($pos)){
            $datas = $manager->get($pos);
            $manager->executeIfMatchCondition($player,
                $datas["if"],
                $datas["match"],
                $datas["else"],
                [
                    "player" => $player,
                    "block" => $block,
                    "event" => $event
                ]
            );
        }
	}


    public function Receive(DataPacketReceiveEvent $event){
        $pk = $event->getPacket();
        $player = $event->getPlayer();
        $name = $player->getName();
        if(!$player->isOp())return;
        if($pk instanceof ModalFormResponsePacket){
            $json = str_replace([",]",",,"], [",\"\"]",",\"\","], $pk->formData);
            $data = json_decode($json);
            Form::onRecive($pk->formId, $player, $data);
        }
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifAPI;
use aieuo\ip\Session;
use aieuo\ip\form\BlockForm;
use aieuo\ip\form\Form;

class BlockForm {
    public function getSelectActionForm(){
        $data = [
            "type" => "form",
            "title" => "block > æ“ä½œé¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                Elements::getButton("ç·¨é›†ã™ã‚‹"),
                Elements::getButton("ç¢ºèªã™ã‚‹"),
                Elements::getButton("å‰Šé™¤ã™ã‚‹"),
                Elements::getButton("ã‚³ãƒ”ãƒ¼ã™ã‚‹"),
                Elements::getButton("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹"),
                Elements::getButton("ã²ã¨ã¤å‰ã®ç”»é¢ã«æˆ»ã‚‹")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if($data === null) return;
        $session = ifAPI::getSession($player);
        switch ($data) {
            case 0:
                $session->setData("action", "edit");
                $player->sendMessage("ç·¨é›†ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                break;
            case 1:
                $session->setData("action", "check");
                $player->sendMessage("ç¢ºèªã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                break;
            case 2:
                $session->setData("action", "del");
                $player->sendMessage("å‰Šé™¤ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                break;
            case 3:
                $session->setData("action", "copy");
                $player->sendMessage("ã‚³ãƒ”ãƒ¼ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                break;
            case 4:
                $session->setValid(false);
                $player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                return;
            case 5:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        $session->setIfType(Session::BLOCK);
        $session->setValid();
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifAPI;
use aieuo\ip\ifPlugin;

use aieuo\ip\Session;
use aieuo\ip\form\BlockForm;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;

class ChainIfForm {
    public function getSelectActionForm(){
        $data = [
            "type" => "form",
            "title" => "chain > æ“ä½œé¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                Elements::getButton("è¿½åŠ "),
                Elements::getButton("ç·¨é›†"),
                Elements::getButton("å‰Šé™¤"),
                Elements::getButton("ä¸€è¦§"),
                Elements::getButton("ã‚­ãƒ£ãƒ³ã‚»ãƒ«"),
                Elements::getButton("ã²ã¨ã¤å‰ã®ç”»é¢ã«æˆ»ã‚‹")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if($data === null) return;
        $session = ifAPI::getSession($player);
        switch ($data) {
            case 0:
                $session->setData("action", "add");
                $form = $this->getAddChainIfForm();
                Form::sendForm($player, $form, $this, "onAddChainIf");
                break;
            case 1:
                $session->setData("action", "edit");
                $form = $this->getEditChainIfForm();
                Form::sendForm($player, $form, $this, "onEditChainIf");
                break;
            case 2:
                $session->setData("action", "del");
                $form = $this->getEditChainIfForm();
                Form::sendForm($player, $form, $this, "onEditChainIf");
                break;
            case 3:
                $form = $this->getChainIfListForm();
                Form::sendForm($player, $form, $this, "onChainIfList");
                break;
            case 4:
                $session->setValid(false);
                $player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                return;
            case 5:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        $session->setIfType(Session::CHAIN);
        $session->setValid();
    }

    public function getAddChainIfForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "chain > è¿½åŠ ",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."é€£æºæ™‚ã«ä½¿ã†åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", ""),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onAddChainIf($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddChainIfForm("Â§cå¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        if($manager->isAdded($data[0])) {
            $form = $this->getAddChainIfForm("Â§cãã®åå‰ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™Â§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("ãã®åå‰ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™");
            return;
        }
        $session->setData("if_key", $data[0]);
        $datas = $manager->repairIF([]);
        $manager->set($data[0], $datas);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }

    public function getEditChainIfForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "chain > ç·¨é›†",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."ç·¨é›†ã™ã‚‹åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", ""),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onEditChainIf($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddChainIfForm("Â§cå¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        if(!$manager->isAdded($data[0])) {
            $form = $this->getAddChainIfForm("Â§cãã®åå‰ã®ç‰©ã¯å­˜åœ¨ã—ã¾ã›ã‚“Â§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("ãã®åå‰ã®ç‰©ã¯å­˜åœ¨ã—ã¾ã›ã‚“");
            return;
        }
        $session->setData("if_key", $data[0]);
        $action = $session->getData("action");
        if($action === "edit") {
            $datas = $manager->repairIF([]);
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form)->getEditIfForm($mes);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        } elseif($action === "del") {
            $form = (new Form())->getConfirmDeleteForm();
            Form::sendForm($player, $form, new Form(), "onDeleteIf");
        }
    }

    public function getChainIfListForm() {
        $datas = ifPlugin::getInstance()->getChainManager()->getAll();
        $buttons = [Elements::getButton("<ã²ã¨ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>")];
        foreach ($datas as $name => $data) {
            $buttons[] = Elements::getButton($name);
        }
        $data = [
            "type" => "form",
            "title" => "ç·¨é›†",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onChainIfList($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        $ifs = array_slice($manager->getAll(), $data-1, 1, true);
        $key = key($ifs);
        $datas = current($ifs);
        $session->setData("if_key", $key);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifAPI;
use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;
use aieuo\ip\form\Form;

class CommandForm {
    public function getSelectActionForm() {
        $data = [
            "type" => "form",
            "title" => "command > æ“ä½œé¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                Elements::getButton("è¿½åŠ ã™ã‚‹"),
                Elements::getButton("ã‚³ãƒžãƒ³ãƒ‰ã ã‘è¿½åŠ ã™ã‚‹"),
                Elements::getButton("ç·¨é›†ã™ã‚‹"),
                Elements::getButton("å‰Šé™¤ã™ã‚‹"),
                Elements::getButton("è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ä¸€è¦§"),
                Elements::getButton("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹"),
                Elements::getButton("ã²ã¨ã¤å‰ã®ç”»é¢ã«æˆ»ã‚‹")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if($data === null) return;
        $session = ifAPI::getSession($player);
        switch ($data) {
            case 0:
                $session->setData("action", "add");
                break;
            case 1:
                $session->setData("action", "add_empty");
                break;
            case 2:
                $session->setData("action", "edit");
                break;
            case 3:
                $session->setData("action", "del");
                break;
            case 4:
                $form = $this->getCommandListForm();
                Form::sendForm($player, $form, $this, "onCommandList");
                return;
            case 5:
                $session->setValid(false);
                $player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                return;
            case 6:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        switch ($data) {
            case 0:
            case 1:
                $form = $this->getAddCommandForm();
                Form::sendForm($player, $form, $this, "onAddCommand");
                break;
            case 2:
            case 3:
            case 4:
                $form = $this->getSelectCommandForm();
                Form::sendForm($player, $form, $this, "onSelectCommand");
                break;
        }
        $session->setIfType(Session::COMMAND);
        $session->setValid();
    }


    public function getAddCommandForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "command > ã‚³ãƒžãƒ³ãƒ‰è¿½åŠ ",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."è¿½åŠ ã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ã®åå‰", "æœ€åˆã®/ã‚’å¤–ã—ã¦"),
                Elements::getInput("ã‚³ãƒžãƒ³ãƒ‰ã®èª¬æ˜Ž"),
                Elements::getDropdown("æ¨©é™", ["opã ã‘", "å…¨å“¡ä½¿ãˆã‚‹"], 1),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onAddCommand($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        if($data[3]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddCommandForm("Â§cå¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
            return;
        }
        if($manager->exists($data[0])){
            $form = $this->getAddCommandForm("Â§cãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™Â§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("Â§cãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™");
            return;
        }
        if($manager->isAdded($data[0])){
            $form = $this->getAddCommandForm("Â§eãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«è¿½åŠ ã—ã¦ã„ã¾ã™Â§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("Â§eãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«è¿½åŠ ã—ã¦ã„ã¾ã™");
            return;
        }
        if($data[1] === "") $data[1] = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™";
        $manager->set($data[0], [], ["perm" => $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true", "desc" => $data[1], ]);
        $manager->register($data[0], $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true", $data[1]);
        if($session->getData("action") == "add_empty"){
            $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
            $session->setValid(false);
            return;
        }
        $session->setData("if_key", $data[0]);
        $session->setData("description", $data[1]);
        $session->setData("permission", $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true");
        $datas = $manager->repairIF([]);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }


    public function getSelectCommandForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "command > ã‚³ãƒžãƒ³ãƒ‰é¸æŠž",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."ã‚³ãƒžãƒ³ãƒ‰ã®åå‰", "æœ€åˆã®/ã‚’å¤–ã—ã¦"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectCommand($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getSelectCommandForm("Â§cå¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onSelectCommand");
            $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        if(!$manager->isAdded($data[0])){
            $form = $this->getSelectCommandForm("Â§cãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“Â§f");
            Form::sendForm($player, $form, $this, "onSelectCommand");
            $player->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
            return;
        }

        $session->setData("if_key", $data[0]);
        $action = $session->getData("action");
        if($action == "edit"){
            $datas = $manager->get($data[0]);
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form)->getEditIfForm($mes);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        }elseif($action == "del"){
            $form = (new Form())->getConfirmDeleteForm();
            Form::sendForm($player, $form, new Form(), "onDeleteIf");
        }
    }

    public function getCommandListForm() {
        $manager = ifPlugin::getInstance()->getCommandManager();
        $commands = $manager->getAll();
        $buttons = [Elements::getButton("<1ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>")];
        foreach ($commands as $command => $value) {
            $buttons[] = Elements::getButton($command);
        }
        $data = [
            "type" => "form",
            "title" => "command > æ“ä½œé¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onCommandList($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        $command = key(array_slice($manager->getAll(), $data - 1, 1, true));
        $session->setData("if_key", $command);
        $datas = $manager->get($command);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

class Elements {
    public static function getLabel($text){
        return [
            "type" => "label",
            "text" => (string)$text
        ];
    }

    public static function getInput($text, $placeholder = "", $default = ""){
        return [
            "type" => "input",
            "text" => (string)$text,
            "default" => (string)$default,
            "placeholder" => (string)$placeholder
        ];
    }

    public static function getToggle($text){
        return [
            "type" => "toggle",
            "text" => (string)$text
        ];
    }

    public static function getDropdown($text, $options, $default = 0){
    	return [
            "type" => "dropdown",
            "text" => (string)$text,
            "options" => $options,
            "default" => $default
        ];
    }

    public static function getButton($text){
    	return [
    		"text" => (string)$text
    	];
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifAPI;
use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;
use aieuo\ip\form\Form;

class EventForm {

	private $events = [
        "PlayerChatEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒãƒ£ãƒƒãƒˆã—ãŸã¨ã",
        "PlayerCommandPreprocessEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã—ãŸã¨ã",
        "PlayerInteractEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ãŸã¨ã",
        "PlayerJoinEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚µãƒ¼ãƒãƒ¼ã«å‚åŠ ã—ãŸã¨ã",
        "PlayerQuitEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚µãƒ¼ãƒãƒ¼ã‹ã‚‰é€€å®¤ã—ãŸã¨ã",
        "BlockBreakEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’å£Šã—ãŸã¨ã",
        "BlockPlaceEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’ç½®ã„ãŸã¨ã",
        "EntityDamageEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’å—ã‘ãŸã¨ã",
        "EntityAttackEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒæ”»æ’ƒã—ãŸã¨ã",
        "PlayerToggleFlightEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ•ãƒ©ã‚¤çŠ¶æ…‹ã‚’åˆ‡ã‚Šæ›¿ãˆãŸã¨ã",
        "PlayerDeathEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒæ­»äº¡ã—ãŸã¨ã",
        "EntityLevelChangeEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ¯ãƒ¼ãƒ«ãƒ‰ã‚’ç§»å‹•ã—ãŸã¨ã",
        "CraftItemEvent" => "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¯ãƒ©ãƒ•ãƒˆã—ãŸã¨ã",
    ];

    public function getEvents() {
    	return $this->events;
    }

    public function getSelectEventForm(){
    	$buttons = [Elements::getButton("1ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹")];
    	foreach ($this->getEvents() as $key => $event) {
    		$buttons[] = Elements::getButton($event);
    	}
        $data = [
            "type" => "form",
            "title" => "event > ã‚¤ãƒ™ãƒ³ãƒˆé¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectEvent($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = (new Form())->getSelectIfTypeForm();
            Form::sendForm($player, $form, new Form(), "onSelectIfType");
            return;
        }
        $eventname = key(array_slice($this->getEvents(), $data-1, 1, true));
        $session->setData("eventname", $eventname);
        $form = $this->getIfListForm($eventname);
        Form::sendForm($player, $form, $this, "onSelectIf");
        $session->setIfType(Session::EVENT);
        $session->setValid();
    }

    public function getIfListForm($event) {
    	$manager = ifPlugin::getInstance()->getEventManager();
    	$datas = $manager->getFromEvent($event);
    	$buttons = [Elements::getButton("<1ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>"), Elements::getButton("<è¿½åŠ ã™ã‚‹>")];
    	foreach ($datas as $n => $data) {
    		$buttons[] = Elements::getButton($n);
    	}
        $data = [
            "type" => "form",
            "title" => "event > $event > é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectIf($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
			$form = $this->getSelectEventForm();
			Form::sendForm($player, $form, $this, "onSelectEvent");
			return;
        }
        $manager = ifPlugin::getInstance()->getEventManager();
        $eventname = $session->getData("eventname");
        if($data === 1) {
            $key = $manager->add_empty($eventname);
        	$session->setData("if_key", $key);
	        $datas = $manager->repairIF([]);
	        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
	        $form = (new Form)->getEditIfForm($mes);
	        Form::sendForm($player, $form, new Form(), "onEditIf");
        	return;
        }
        $session->setData("if_key", $data - 2);
        $datas = $manager->get($data - 2, ["eventname" => $eventname]);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

class ExportForm {
    public function getExportForm($mes = ""){
        $data = [
            "type" => "custom_form",
            "title" => "å…±æœ‰ç”¨ãƒ•ã‚¡ã‚¤ãƒ«ä½œæˆ",
            "content" => [
                Elements::getInput(($mes === "" ? "" : $mes."\n")."ã‚¿ã‚¤ãƒˆãƒ«"),
                Elements::getInput("ä½œæˆè€…"),
                Elements::getInput("èª¬æ˜Ž"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onExport($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if($data[3]) {
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form())->getEditIfForm($mes);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        	return;
        }
        if($data[0] == "" or $data[1] == "" or $data[2] == "") {
            $form = $this->getExportForm("Â§cå¿…è¦äº‹é …ã‚’è¨˜å…¥ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onExport");
            $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
            return;
        }
        $datas["type"] = $type;
        $datas["options"] = $options;
        $export = [
        	"name" => $data[0],
        	"author" => $data[1],
        	"details" => $data[2],
            "plugin_version" => ifPlugin::VERSION,
        	"ifs" => [
        		$key => $datas
        	]
        ];
        $filename = $data[0]."_".$data[1]."_".$type."_".$key.".json";
        $path = ifPlugin::getInstance()->getDataFolder()."exports/".$filename;
        file_put_contents($path, json_encode($export, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
        $player->sendMessage($filename."ã¨ã—ã¦ä¿å­˜ã—ã¾ã—ãŸ");
        $session->setValid(false);
    }
}<?php

namespace aieuo\ip\form;

use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;

use aieuo\ip\ifPlugin;
use aieuo\ip\ifAPI;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

use aieuo\ip\conditions\Condition;
use aieuo\ip\conditions\ConditionFactory;
use aieuo\ip\processes\Process;
use aieuo\ip\processes\ProcessFactory;

class Form {

    private static $forms = [];

    public static function sendForm($player, $form, $class, $func){
        while(true) {
            $id = mt_rand(0, 999999999);
            if(!isset(self::$forms[$id])) break;
        }
        self::$forms[$id] = [$class, $func];
        $pk = new ModalFormRequestPacket();
        $pk->formId = $id;
        $pk->formData = $form;
        $player->dataPacket($pk);
    }

    public static function onRecive($id, $player, $datas) {
        if(isset(self::$forms[$id])) {
            call_user_func_array(self::$forms[$id], [$player, $datas]);
            unset(self::$forms[$id]);
        }
    }

//////////////////////////////////////////////////////////////
    public static function encodeJson($data){
        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE);
        return $json;
    }

//////////////////////////////////////////////////////////////
    public function getBlockForm() {
        return new BlockForm();
    }

    public function getCommandForm() {
        return new CommandForm();
    }

    public function getEventForm() {
        return new EventForm();
    }

    public function getChainForm() {
        return new ChainIfForm();
    }

    public function getExportForm() {
        return new ExportForm();
    }

    public function getImportForm() {
        return new ImportForm();
    }

    public function getSelectIfTypeForm(){
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                Elements::getButton("ãƒ–ãƒ­ãƒƒã‚¯"),
                Elements::getButton("ã‚³ãƒžãƒ³ãƒ‰"),
                Elements::getButton("ã‚¤ãƒ™ãƒ³ãƒˆ"),
                Elements::getButton("ãƒã‚§ãƒ¼ãƒ³"),
                Elements::getButton("ãƒ•ã‚¡ã‚¤ãƒ«ã‚¤ãƒ³ãƒãƒ¼ãƒˆ"),
                Elements::getButton("çµ‚äº†")
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public function onSelectIfType($player, $data) {
        if($data === null) return;
        $session = ifAPI::getSession($player);
        switch ($data) {
            case 0:
                $session->setIfType(Session::BLOCK);
                $form = $this->getBlockForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getBlockForm(), "onSelectAction");
                break;
            case 1:
                $session->setIfType(Session::COMMAND);
                $form = $this->getCommandForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getCommandForm(), "onSelectAction");
                break;
            case 2:
                $session->setIfType(Session::EVENT);
                $form = $this->getEventForm()->getSelectEventForm();
                Form::sendForm($player, $form, $this->getEventForm(), "onselectEvent");
                break;
            case 3:
                $session->setIfType(Session::CHAIN);
                $form = $this->getChainForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getChainForm(), "onselectAction");
                break;
            case 4:
                $form = $this->getImportForm()->getImportListForm();
                Form::sendForm($player, $form, $this->getImportForm(), "onImportList");
                break;
            case 5:
                $session->setValid(false);
                break;
        }
    }

    public function getEditIfForm($mes) {
        $data = [
            "type" => "form",
            "title" => "IFç·¨é›†",
            "content" => $mes,
            "buttons" => [
                Elements::getButton("ã‚‚ã—~ã‚’ç·¨é›†ã™ã‚‹"),
                Elements::getButton("æ¡ä»¶ã«åˆã£ãŸæ™‚ã‚’ç·¨é›†ã™ã‚‹"),
                Elements::getButton("æ¡ä»¶ã«åˆã‚ãªã‹ã£ãŸæ™‚ã‚’ç·¨é›†ã™ã‚‹"),
                Elements::getButton("å‰Šé™¤ã™ã‚‹"),
                Elements::getButton("ãƒ•ã‚¡ã‚¤ãƒ«å‡ºåŠ›ã™ã‚‹"),
                Elements::getButton("çµ‚äº†")
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onEditIf($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if($data == 0) {
            $form = $this->getEditContentsForm($datas["if"]);
            $session->setData("type", "if");
        } elseif($data == 1) {
            $form = $this->getEditContentsForm($datas["match"]);
            $session->setData("type", "match");
        } elseif($data == 2) {
            $form = $this->getEditContentsForm($datas["else"]);
            $session->setData("type", "else");
        } elseif($data == 3) {
            $form = $this->getConfirmDeleteForm();
            Form::sendForm($player, $form, $this, "onDeleteIf");
            return;
        } elseif($data == 4) {
            $form = $this->getExportForm()->getExportForm();
            Form::sendForm($player, $form, $this->getExportForm(), "onExport");
            return;
        } else {
            $session->setValid(false);
            return;
        }
        Form::sendForm($player, $form, $this, "onEditIfContents");
    }

    public function getEditContentsForm($datas, $mes = ""){
        $data = [
            "type" => "form",
            "title" => "ç·¨é›†",
            "content" => ($mes === "" ? "" : $mes."\n")."Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => []
        ];
        $data["buttons"] = [Elements::getButton("<1ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>"), Elements::getButton("<è¿½åŠ ã™ã‚‹>")];
        foreach ($datas as $key => $value) {
            if($value["id"] < 100) {
                $content = Condition::get($value["id"]);
            } else {
                $content = Process::get($value["id"]);
            }
            $content->setValues($content->parse($value["content"]));
            $message = $content->getMessage();
            $data["buttons"][] = Elements::getButton($message === false ? $content->getDescription() : $message);
        }
        $data = self::encodeJson($data);
        return $data;
    }

    public function onEditIfContents($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if($data == 0) {
            // ã²ã¨ã¤å‰ã®formã«æˆ»ã‚‹
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = $this->getEditIfForm($mes);
            Form::sendForm($player, $form, $this, "onEditIf");
            return;
        }
        if($data == 1) {
            // æ–°ã—ãè¿½åŠ ã™ã‚‹
            $form = $this->getAddContentsForm($session->getData("type"));
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }

        // è¿½åŠ ã•ã‚Œã¦ã„ã‚‹ã‚‚ã®ã‚’é¸æŠžã—ãŸ
        $ifData = $datas[$session->getData("type")][$data - 2];
        if($session->getData("type") == "if") {
            $datas = Condition::get($ifData["id"]);
        } else {
            $datas = Process::get($ifData["id"]);
        }
        $session->setData("contents", $datas);
        $session->setData("num", $data - 2);
        $form = $datas->getEditForm((string)$ifData["content"]);
        Form::sendForm($player, $form, $this, "onUpdateContent");
    }

    public function getAddContentsForm($type, $mes = ""){
        if($type == "if"){
            $datas = ConditionFactory::getAll();
        }else{
            $datas = ProcessFactory::getAll();
        }
        $buttons[] = Elements::getButton("<ã²ã¨ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>");
        $buttons[] = Elements::getButton("<æ¤œç´¢ã™ã‚‹>");
        foreach ($datas as $data) {
            $buttons[] = Elements::getButton($data->getName());
        }
        $data = [
            "type" => "form",
            "title" => "ç·¨é›† > è¿½åŠ ",
            "content" => ($mes === "" ? "" : $mes."\n")."Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public function onAddContent($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        if($data == 0) {
            $key = $session->getData("if_key");
            $datas = $manager->get($key, $options);
            $form = $this->getEditContentsForm($datas[$session->getData("type")]);
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        if($data == 1) {
            $form = $this->getSearchForm();
            Form::sendForm($player, $form, $this, "onSearch");
            return;
        }
        $data -= 2;
        if($session->getData("type") == "if") {
            $all = ConditionFactory::getAll();
            $datas = Condition::get(current(array_slice($all, $data, 1, true))->getId());
        } else {
            $all = ProcessFactory::getAll();
            $datas = Process::get(current(array_slice($all, $data, 1, true))->getId());
        }
        $session->setData("contents", $datas);
        $form = $datas->getEditForm();
        Form::sendForm($player, $form, $this, "onEdit");
    }

    public function onEdit($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $content = $session->getData("contents");
        $datas = $content->parseFormData($data);
        if($datas["cancel"]) {
            $form = $this->getAddContentsForm($session->getData("type"));
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }
        if($datas["delete"]) {
            $player->sendMessage("Â§cã¾ã è¿½åŠ ã—ã¦ã„ãªã„ã®ã§å‰Šé™¤ã§ãã¾ã›ã‚“");
            $form = $this->getAddContentsForm($session->getData("type"), "Â§cã¾ã è¿½åŠ ã—ã¦ã„ãªã„ã®ã§å‰Šé™¤ã§ãã¾ã›ã‚“Â§f");
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }
        if($datas["status"] === null) {
            $form = $content->getEditForm($datas["contents"], "Â§cå¿…è¦äº‹é …ã‚’è¨˜å…¥ã—ã¦ãã ã•ã„Â§f\n");
            Form::sendForm($player, $form, $this, "onEdit");
            return;
        }
        $mes = "Â§bè¿½åŠ ã—ã¾ã—ãŸÂ§f";
        if($datas["status"] === false) $mes = "Â§eè¿½åŠ ã—ã¾ã—ãŸãŒã€æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ãªã„å¯èƒ½æ€§ãŒã‚ã‚Šã¾ã™Â§f";
        $key = $session->getData("if_key");
        $manager->add($key, $session->getData("type"), $content->getId(), $datas["contents"], $options);
        $contents = $manager->get($key, $options);
        $form = $this->getEditContentsForm($contents[$session->getData("type")], $mes);
        Form::sendForm($player, $form, $this, "onEditIfContents");
        $player->sendMessage($mes);
    }

    public function onUpdateContent($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $content = $session->getData("contents");
        $datas = $content->parseFormData($data);
        if($datas["cancel"]) {
            $key = $session->getData("if_key");
            $form = $this->getEditContentsForm($manager->get($key, $options)[$session->getData("type")]);
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        if($datas["delete"]) {
            $form = $this->getConfirmDeleteForm();
            Form::sendForm($player, $form, $this, "onDeleteContent");
            return;
        }
        if($datas["status"] === null) {
            $form = $content->getEditForm($datas["contents"], "Â§cå¿…è¦äº‹é …ã‚’è¨˜å…¥ã—ã¦ãã ã•ã„Â§f\n");
            Form::sendForm($player, $form, $this, "onEdit");
            return;
        }

        $mes = "Â§bå¤‰æ›´ã—ã¾ã—ãŸÂ§f";
        if($datas["status"] === false) $mes = "Â§eå¤‰æ›´ã—ã¾ã—ãŸãŒã€æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ãªã„å¯èƒ½æ€§ãŒã‚ã‚Šã¾ã™Â§f";
        $key = $session->getData("if_key");
        $manager->updateContent($key, $session->getData("type"), $session->getData("num"), $datas["contents"], $options);
        $contents = $manager->get($key, $options);
        $form = $this->getEditContentsForm($contents[$session->getData("type")], $mes);
        Form::sendForm($player, $form, $this, "onEditIfContents");
        $player->sendMessage($mes);
    }

    public function getConfirmDeleteForm() {
        $data = [
            "type" => "modal",
            "title" => "å‰Šé™¤",
            "content" => "æœ¬å½“ã«å‰Šé™¤ã—ã¾ã™ã‹?\nå‰Šé™¤ã™ã‚‹ã¨å…ƒã«æˆ»ã›ã¾ã›ã‚“",
            "button1" => "ã¯ã„",
            "button2" => "ã„ã„ãˆ"
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onDeleteContent($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);

        $key = $session->getData("if_key");
        if($data) {
            $manager->del($key, $session->getData("type"), $session->getData("num"), $options);
            $form = $this->getEditContentsForm($manager->get($key, $options)[$session->getData("type")], "Â§bå‰Šé™¤ã—ã¾ã—ãŸÂ§f");
            Form::sendForm($player, $form, $this, "onEditIfContents");
            $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
        } else {
            $ifData = $contents[$session->getData("type")][$session->getData("num")];
            $form = $manager->get($key, $options)->getEditForm($ifData["contents"], "Â§eå‰Šé™¤ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸÂ§f\n");
            Form::sendForm($player, $form, $this, "onEdit");
            $player->sendMessage("å‰Šé™¤ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
        }
    }

    public function onDeleteIf($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);

        if($data) {
            $manager->remove($session->getData("if_key"), $options);
            $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
        } else {
            $player->sendMessage("å‰Šé™¤ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
        }
        $session->setValid(false);
    }

    public function getSearchForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "IFæ¤œç´¢",
            "content" => [
                Elements::getLabel("åå‰ã§æ¤œç´¢ã—ã¾ã™".(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("æ¤œç´¢ã™ã‚‹è¨€è‘‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„")
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onSearch($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1] === "") {
            $form = $this->getSearchForm("Â§cå¿…è¦äº‹é …ã‚’è¨˜å…¥ã—ã¦ãã ã•ã„Â§f");
            Form::sendForm($player, $form, $this, "onSearch");
            return;
        }
        if($session->getData("type") == "if") {
            $all = ConditionFactory::getAll();
        } else {
            $all = ProcessFactory::getAll();
        }
        $keywords = explode(" ", $data[1]);
        $result = array_filter($all, function($item) use($keywords) {
            $contains = true;
            foreach ($keywords as $keyword) {
                if(strpos($item->getName(), $keyword) === false) $contains = false;
            }
            return($contains);
        });
        $session->setData("searchResult", $result);

        $buttons[] = Elements::getButton("<ã²ã¨ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>");
        foreach ($result as $item) {
            $buttons[] = Elements::getButton($item->getName());
        }
        $data = [
            "type" => "form",
            "title" => "ç·¨é›† > è¿½åŠ ",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        Form::sendForm($player, self::encodeJson($data), $this, "onSearchResult");
    }

    public function onSearchResult($player, $data) {
        $session = ifAPI::getSession($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        if($data == 0) {
            $key = $session->getData("if_key");
            $datas = $manager->get($key, $options);
            $form = $this->getEditContentsForm($datas[$session->getData("type")]);
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        $data -= 1;
        $all = $session->getData("searchResult");
        if($session->getData("type") == "if") {
            $datas = Condition::get(current(array_slice($all, $data, 1, true))->getId());
        } else {
            $datas = Process::get(current(array_slice($all, $data, 1, true))->getId());
        }
        $session->setData("contents", $datas);
        $form = $datas->getEditForm();
        Form::sendForm($player, $form, $this, "onEdit");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifAPI;
use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

class ImportForm {
	public function getImportListForm($mes = "") {
		$buttons = [Elements::getButton("<ã²ã¨ã¤å‰ã®ãƒšãƒ¼ã‚¸ã«æˆ»ã‚‹>")];
		$files = glob(ifPlugin::getInstance()->getDataFolder()."imports/*.json");
		foreach($files as $file){
			if(is_dir($file)) continue;
			$datas = json_decode(file_get_contents($file), true);
			$buttons[] = Elements::getButton($datas["name"]." | ".$datas["author"]);
		}
		$data = [
			"type" => "form",
			"title" => "ãƒ•ã‚¡ã‚¤ãƒ«é¸æŠž",
			"content" => ($mes === "" ? "" : $mes."\n")."Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
			"buttons" => $buttons
		];
		$json = Form::encodeJson($data);
		return $json;
	}

	public function onImportList($player, $data) {
        $session = ifAPI::getSession($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data == 0) {
			$data = (new Form())->getSelectIfTypeForm();
			Form::sendForm($player, $data, new Form(), "onSelectIfType");
			return;
		}
		$files = glob(ifPlugin::getInstance()->getDataFolder()."imports/*.json");
		if(!isset($files[$data - 1])) {
			$form = $this->getImportListForm("ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€ã‚‚ã†ä¸€åº¦é¸æŠžã—ã¦ãã ã•ã„");
			Form::sendForm($player, $form, $this, "onImportList");
			return;
		}
		$path = $files[$data - 1];
		$session->setData("path", $path);
		$form = $this->getImportForm(json_decode(file_get_contents($path), true));
		Form::sendForm($player, $form, $this, "onImport");
	}

	public function getImportForm($datas) {
		$mes = $datas["name"]."\nä½œæˆè€…: ".$datas["author"]."\n".$datas["details"]."\n";
		foreach ($datas["ifs"] as $key => $value) {
			$mes .= "---------------------------\n";
			$mes .= "Â§l".$key."Â§rÂ§f\n".Messages::createMessage($value["if"], $value["match"], $value["else"])."\n";
		}
		$data = [
			"type" => "custom_form",
			"title" => "ãƒ•ã‚¡ã‚¤ãƒ«ã‚¤ãƒ³ãƒãƒ¼ãƒˆ > ".$datas["name"],
			"content" => [
				Elements::getLabel($mes),
				Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
			]
		];
		$json = Form::encodeJson($data);
		return $json;
	}

	public function onImport($player, $data) {
        $session = ifAPI::getSession($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data[1]) {
			$form = $this->getImportListForm("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
			Form::sendForm($player, $form, $this, "onImportList");
			return;
		}
		$file = json_decode(file_get_contents($session->getData("path")), true);
		$this->importDatas($player, $file);
	}

	public function importDatas($player, $file, $count = 0) {
        $session = ifAPI::getSession($player);
		foreach ($file["ifs"] as $key => $datas) {
			if($datas["type"] === Session::BLOCK) {
				$manager = ifPlugin::getInstance()->getBlockManager();

				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])) {
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				]);
				$count ++;

			} elseif($datas["type"] === Session::COMMAND) {
				$manager = ifPlugin::getInstance()->getCommandManager();

				if(!$manager->isAdded($key) and $manager->exists($key)) continue;
				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])){
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				], [
					"desc" => $datas["description"],
					"perm" => $datas["permission"]
				]);
				$manager->register($key, $datas["description"], $datas["permission"]);
				$count ++;

			} elseif($datas["type"] === Session::EVENT) {
				$manager = ifPlugin::getInstance()->getEventManager();
				$manager->addByEvent($datas["options"]["eventname"], $datas + ["author" => $file["author"]]);
				$count ++;
			} elseif($datas["type"] === Session::CHAIN) {
				$manager = ifPlugin::getInstance()->getChainManager();

				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])) {
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				]);
				$count ++;

			}
			unset($file["ifs"][$key]);
		}
		$player->sendMessage($count."å€‹ã®IFã‚’è¿½åŠ ã—ã¾ã—ãŸ");
		$session->setValid(false);
	}

	public function getConfirmOverwriteForm($name) {
		$data = [
			"type" => "modal",
			"title" => "ä¸Šæ›¸ã",
			"content" => $name."ã¯æ—¢ã«å­˜åœ¨ã—ã¾ã™ã€ä¸Šæ›¸ãã—ã¾ã™ã‹?\nä¸Šæ›¸ãã™ã‚‹ã¨ä»¥å‰ã®ç‰©ã¯å¾©å…ƒã§ãã¾ã›ã‚“ã€‚",
			"button1" => "ã¯ã„",
			"button2" => "ã„ã„ãˆ"
		];
		$data = Form::encodeJson($data);
		return $data;
	}

	public function onConfirmOverwrite($player, $data) {
        $session = ifAPI::getSession($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data) {
			if(($overwrite = $session->getData("overwrite")) === "") {
				$session->setData("overwrite", [$session->getData("if_key") => true]);
			} else {
				$overwrite[$session->getData("if_key")] = true;
				$session->setData("overwrite", $overwrite);
			}
			$this->importDatas($player, $session->getData("file"), $session->getData("count"));

		} else {
			if(($overwrite = $session->getData("overwrite")) === "") {
				$session->setData("overwrite", [$session->getData("if_key") => false]);
			} else {
				$overwrite[$session->getData("if_key")] = false;
				$session->setData("overwrite", $overwrite);
			}
			$this->importDatas($player, $session->getData("file"), $session->getData("count"));
		}
	}
}<?php

namespace aieuo\ip;

use aieuo\ip\manager\ifManager;

use pocketmine\Player;
use pocketmine\Server;
use pocketmine\item\Item;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\lang\TranslationContainer;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Entity;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\event\entity\EntityDamageEvent;

use aieuo\ip\task\DelayedCommandTask;
use aieuo\ip\variable\Variable;

use aieuo\ip\conditions\Condition;
use aieuo\ip\processes\Process;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class ifAPI {

    private static $sessions = [];

    public function executeIfMatchCondition($player, $datas1, $datas2, $datas3, $args = []){
        $stat = "2";
        foreach($datas1 as $datas){
            $result = ($co = Condition::get($datas["id"]))
                        ->setPlayer($player)
                        ->setValues(
                            $co->parse(
                                ifPlugin::getInstance()
                                  ->getVariableHelper()
                                  ->replaceVariables($datas["content"], $this->getReplaceDatas($args))
                            )
                        )->check();
            if($result === Condition::NOT_FOUND){
                $player->sendMessage("Â§cã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸ(id: ".$datas["id"]."ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“)");
                return false;
            }elseif($result === Condition::ERROR){
                return false;
            }elseif($result === Condition::NOT_MATCHED){
                $stat = "3";
            }
        }
        foreach (${"datas".$stat} as $datas) {
            $process = Process::get($datas["id"]);
            if($datas["id"] === Process::EVENT_CANCEL) {
                $process->setValues($args["event"])->execute();
                continue;
            }
            $process->setPlayer($player)
              ->setValues(
                $process->parse(
                    ifPlugin::getInstance()
                      ->getVariableHelper()
                      ->replaceVariables($datas["content"], $this->getReplaceDatas($args))
                )
              )->execute();
        }
        return true;
    }

    public function getReplaceDatas($datas) {
        $player = $datas["player"];
        $server = Server::getInstance();
        $variableHelper = ifPlugin::getInstance()->getVariableHelper();
        $onlines = [];
        foreach ($server->getOnlinePlayers() as $p) {
            $onlines[] = $p->getName();
        }
        $ops = [];
        foreach ($server->getOps()->getAll() as $p => $value) {
            $ops[] = $p;
        }
        $variables = [
            "player" => new StringVariable("player", $player->__toString()),
            "player_name" => new StringVariable("player_name", $player->getName()),
            "nametag" => new StringVariable("nametag", $player->getDisplayName()),
            "player_pos" => new StringVariable("player_pos", $player->x.",".$player->y.",".$player->z.",".$player->level->getFolderName()),
            "player_x" => new NumberVariable("player_x", $player->x),
            "player_y" => new NumberVariable("player_y", $player->y),
            "player_z" => new NumberVariable("player_z", $player->z),
            "player_level" => new StringVariable("player_level", $player->level->getFolderName()),
            "firstplayed" => new NumberVariable("firstplayed", $player->getFirstPlayed()),
            "lastplayed" => new NumberVariable("lastplayed", $player->getLastPlayed()),
            "hand_index" => new NumberVariable("hand_index", $player->getInventory()->getHeldItemIndex()),
            "hand_item" => new StringVariable("hand_item", $player->getInventory()->getItemInHand()->__toString()),
            "hand_name" => new StringVariable("hand_name", $player->getInventory()->getItemInHand()->getName()),
            "hand_id" => new NumberVariable("hand_id", $player->getInventory()->getItemInHand()->getId()),
            "hand_damage" => new NumberVariable("hand_damage", $player->getInventory()->getItemInHand()->getDamage()),
            "hand_count" => new NumberVariable("hand_count", $player->getInventory()->getItemInHand()->getCount()),
            "server_name" => new StringVariable("server_name", $server->getName()),
            "microtime" => new NumberVariable("microtime", microtime(true)),
            "date" => new StringVariable("date", date("m/d h:i:s")),
            "default_level" => new StringVariable("default_level", $server->getDefaultLevel()->getFolderName()),
            "onlines" => new ListVariable("onlines", $onlines),
            "ops" => new ListVariable("ops", $ops)
        ];
        return $variables;
    }

    /**
     * @param  Player $player
     * @return Session
     */
    public static function getSession(Player $player) {
        if(!isset(self::$sessions[$player->getName()])) self::$sessions[$player->getName()] = new Session();
        return self::$sessions[$player->getName()];
    }
}<?php
namespace aieuo\ip;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\utils\Config;

use pocketmine\event\player\PlayerInteractEvent;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\PluginCommand;

use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;

use aieuo\ip\commands\ifCommand;
use aieuo\ip\manager\ifManager;
use aieuo\ip\manager\BlockManager;
use aieuo\ip\manager\CommandManager;
use aieuo\ip\manager\EventManager;
use aieuo\ip\manager\ChainIfManager;
use aieuo\ip\utils\Messages;
use aieuo\ip\form\Form;
use aieuo\ip\economy\EconomyLoader;
use aieuo\ip\economy\EconomyAPILoader;
use aieuo\ip\economy\MoneySystemLoader;
use aieuo\ip\economy\PocketMoneyLoader;
use aieuo\ip\ifAPI;
use aieuo\ip\task\SaveTask;
use aieuo\ip\variable\VariableHelper;

use aieuo\ip\conditions\ConditionFactory;
use aieuo\ip\processes\ProcessFactory;

class ifPlugin extends PluginBase implements Listener{

    const VERSION = "3.0.3";

    private static $instance;

    public function onEnable(){
        $this->getServer()->getPluginManager()->registerEvents(new EventListener($this),$this);

        $this->getServer()->getCommandMap()->register("ifPlugin", new ifCommand($this));

        if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0721, true);
        if(!file_exists($this->getDataFolder()."exports")) @mkdir($this->getDataFolder()."exports", 0721, true);
        if(!file_exists($this->getDataFolder()."imports")) @mkdir($this->getDataFolder()."imports", 0721, true);
        $this->config = new Config($this->getDataFolder()."config.yml", Config::YAML, [
            "wait" => 0,
            "save_time" => 10*20*60
        ]);
        $this->wait = $this->config->get("wait");

        $this->loadEconomySystemPlugin();

        $this->command = new CommandManager($this);
        $this->block = new BlockManager($this);
        $this->event = new EventManager($this);
        $this->chain = new ChainIfManager($this);

        $this->api = new ifAPI();

        $this->variables = new VariableHelper($this);
        $this->variables->loadDataBase();

        $savetime = (int)$this->config->get("save_time", 10*20*60);
        $this->getScheduler()->scheduleRepeatingTask(new SaveTask($this), (int)$savetime);

        self::$instance = $this;

        ConditionFactory::init();
        ProcessFactory::init();
    }

    public function onDisable(){
        $this->command->save();
        $this->block->save();
        $this->event->save();
        $this->chain->save();
        $this->variables->save();
    }

    public static function getInstance(){
        return self::$instance;
    }

    public function getBlockManager() : BlockManager{
        return $this->block;
    }

    public function getCommandManager() : CommandManager{
        return $this->command;
    }

    public function getEventManager() : EventManager{
        return $this->event;
    }

    public function getChainManager() : ChainIfManager{
        return $this->chain;
    }

    public function getAPI() : ifAPI{
        return $this->api;
    }

    public function getVariableHelper() : VariableHelper{
        return $this->variables;
    }

    public function getEconomy() : ?EconomyLoader {
        return $this->economy;
    }

    public function loadEconomySystemPlugin(){
        if(($plugin = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")) !== null){
            $this->economy = new EconomyAPILoader($plugin);
            $this->getServer()->getLogger()->info("[if] EconomyAPIã‚’è¦‹ã¤ã‘ã¾ã—ãŸ");
        }elseif(($plugin = $this->getServer()->getPluginManager()->getPlugin("MoneySystem")) !== null){
            $this->economy = new MoneySystemLoader($plugin);
            $this->getServer()->getLogger()->info("[if] MoneySystemã‚’è¦‹ã¤ã‘ã¾ã—ãŸ");
        }elseif(($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null){
            $this->economy = new PocketMoneyLoader($plugin);
            $this->getServer()->getLogger()->info("[if] PocketMoneyã‚’è¦‹ã¤ã‘ã¾ã—ãŸ");
        }else{
            $this->economy = null;
            $this->getServer()->getLogger()->warning("[if] çµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“ã§ã—ãŸ");
        }
    }

    public function getManagerBySession($session) {
        $type = $session->getIfType();
        if($type === Session::BLOCK) {
            $manager = $this->getBlockManager();
        }elseif($type === Session::COMMAND) {
            $manager = $this->getCommandManager();
        }elseif($type === Session::EVENT) {
            $manager = $this->getEventManager();
        }elseif($type === Session::CHAIN) {
            $manager = $this->getChainManager();
        }
        return $manager;
    }

    public function getOptionsBySession($session) {
        $type = $session->getIfType();
        if($type === Session::BLOCK) {
            $options = [];
        }elseif($type === Session::COMMAND) {
            $options = ["desc" => $session->getData("description"), "perm" => $session->getData("permission")];
        }elseif($type === Session::EVENT) {
            $options = ["eventname" => $session->getData("eventname")];
        }elseif($type === Session::CHAIN) {
            $options = [];
        }
        return $options;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\block\SignPost;
use pocketmine\tile\Sign;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class BlockManager extends ifManager{

	public function __construct($owner){
		parent::__construct($owner ,"blocks");
	}

    public function set($key, $datas = [], $args = []){
        $datas = $this->repairIF($datas);
        parent::set($key, $datas);
    }

    public function getPosition($block){
        return $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
    }

    public function getReplaceDatas($datas) {
        $result = parent::getReplaceDatas($datas);
        $block = $datas["block"];
        $event = $datas["event"];
        $variables = [
            "block" => new StringVariable("block", $block->__toString()),
            "block_name" => new StringVariable("block_name", $block->getName()),
            "block_id" => new NumberVariable("block_id", $block->getId()),
            "block_damage" => new NumberVariable("block_damage", $block->getDamage()),
            "block_ids" => new StringVariable("block_ids", $block->getId().":".$block->getDamage()),
            "block_pos" => new StringVariable("block_pos", $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName()),
            "block_x" => new NumberVariable("block_x", $block->x),
            "block_y" => new NumberVariable("block_y", $block->y),
            "block_z" => new NumberVariable("block_z", $block->z),
            "block_level" => new StringVariable("block_level", $block->level->getFolderName()),
            "touch_face" => new NumberVariable("touch_face", $event->getFace())
        ];
        if($block instanceof SignPost) {
            $sign = $block->level->getTile($block);
            if($sign instanceof Sign) {
                $variables["sign_lines"] = new ListVariable("sign_lines", $sign->getText());
            }
        }
        return array_merge($result, $variables);
    }
}<?php

namespace aieuo\ip\manager;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class ChainIfManager extends ifManager{

	public function __construct($owner){
		parent::__construct($owner ,"chains");
	}

    public function set($key, $datas = [], $args = []){
        $datas = $this->repairIF($datas);
        parent::set($key, $datas);
    }

    public function getReplaceDatas($datas) {
        $result = parent::getReplaceDatas($datas);
        if(isset($datas["count"])) $result["i"] = new NumberVariable("i", $datas["count"]);
        if(isset($datas["origin"])) {
            $origin = $datas["origin"];
            $variables = [
                "origin_name" => new StringVariable("origin_name", $origin->getName()),
                "origin_pos" => new StringVariable("origin_pos", $origin->x.",".$origin->y.",".$origin->z.",".$origin->level->getFolderName()),
                "origin_x" => new NumberVariable("origin_x", $origin->x),
                "origin_y" => new NumberVariable("origin_y", $origin->y),
                "origin_z" => new NumberVariable("origin_z", $origin->z),
                "origin_level" => new StringVariable("origin_level", $origin->level->getFolderName())
            ];
            $result = array_merge($result, $variables);
        }
        return $result;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\command\Command;
use pocketmine\command\PluginCommand;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class CommandManager extends ifManager {

    private $command_list = [];

	public function __construct($owner){
        parent::__construct($owner, "commands");
        $this->registerCommands();
	}

    public function set($key, $datas = [], $args = []){
        $datas = $this->repairIF($datas);
        if($args["desc"] === "") $args["desc"] = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™";
        if($args["perm"] === "") $args["perm"] = "ifplugin.customcommand.op";
        $datas["description"] = $args["desc"];
        $datas["permission"] = $args["perm"];
        parent::set($key, $datas);
    }

    public function add($key, $type, $id, $content, $args = []){
        $datas = [];
        if($this->isAdded($key))$datas = $this->get($key);
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->register($key, $args["desc"], $args["perm"]);
        $this->set($key, $datas, $args);
    }

    public function remove($key){
        $this->unregister($key);
        parent::remove($key);
    }

    public function registerCommands(){
        foreach($this->getAll() as $command => $value){
            $permission = $value["permission"];
            switch ($permission) {
                case 'ifplugin.customcommand.op':
                case 'ifplugin.customcommand.true':
                    break;
                case true:
                case 'true':
                case 'default':
                    $permission = "ifplugin.customcommand.true";
                    break;
                default:
                    $permission = "ifplugin.customcommand.op";
                    break;
            }
            if($this->isSubcommand($command)) $command = $this->getOriginCommand($command);
            if(!$this->exists($command)) {
                $this->register($command, $permission, $value["description"]);
            }
        }
    }

    public function register($command, $permission = "ifplugin.customcommand.op", $description = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™"){
        if($this->isSubcommand($command)) $command = $this->getOriginCommand($command);
        if(!$this->exists($command)){
            $newCommand = new PluginCommand($command, $this->getOwner());
            $newCommand->setDescription($description);
            $newCommand->setPermission($permission);
            $this->getServer()->getCommandMap()->register("ifPlugin", $newCommand);
            $this->command_list[$command] = $newCommand;
            return true;
        }
        return false;
    }

    public function unregister($command){
        var_dump($command);
        $count = count($this->getSubcommands($command));
        if(!$this->isSubcommand($command) and $this->isAdded($command)) $count ++;
        if($count <= 1) {
            $this->getServer()->getCommandMap()->unregister($this->command_list[$command]);
        }
        unset($this->command_list[$command]);
    }

    public function exists($command) {
        $exist = $this->getServer()->getPluginCommand($command);
        if($exist === null)return false;
        return true;
    }

    public function isSubcommand($command){
    	$subcommand = false;
    	if(strpos($command, " ") !== false)$subcommand = true;
    	return $subcommand;
    }

    public function getSubcommands($command){
    	$array = [];
    	$command = explode(" ", $command)[0];
    	$commands = $this->getAll();
    	foreach ($commands as $cmd => $value) {
    		$cmds = explode(" ", $cmd);
    		if(array_shift($cmds) == $command){
    			if(isset($cmds[0])){
    				$sub = implode(" ", $cmds);
        			$array[] = $sub;
    			}
    		}
    	}
    	return $array;
    }

    public function getOriginCommand($command){
    	if(!$this->isSubcommand($command)) return $command;
    	$commands = explode(" ", $command);
    	return $commands[0];
    }

    public function getReplaceDatas($datas) {
        $result = parent::getReplaceDatas($datas);
        $command = $datas["command"];
        $cmds = explode(" ", substr($command, 1));
        $result["cmd"] = new StringVariable("cmd", array_shift($cmds));
        $result["args"] = new ListVariable("args", $cmds);
        return $result;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\Player;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\block\SignPost;
use pocketmine\tile\Sign;

use aieuo\ip\ifPlugin;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class EventManager extends ifManager{

	public function __construct($owner){
        parent::__construct($owner, "events");
    }

    public function get($key, $args = []){
        $datass = $this->getFromEvent($args["eventname"]);
        if(!isset($datass[$key]))return [];
        $datas = $datass[$key];
        $datas = $this->repairIF($datas);
        return $datas;
    }

    public function add($key, $type, $id, $content, $args = []){
        $datas = $this->getFromEvent($args["eventname"]);
        $datas[$key][$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->set($args["eventname"], $datas);
    }

    public function getCount($event){
        $datas = $this->getFromEvent($event);
        return count($datas);
    }

    public function add_empty($event){
        $datas = $this->getFromEvent($event);
        $data = [
            "if" => [],
            "match" => [],
            "else" => []
        ];
        $datas[] = $data;
        $this->set($event, $datas);
        return count($datas) -1;
    }

    public function getFromEvent($event){
        $datas = [];
        if(isset(($all = $this->getAll())[$event]))$datas = $all[$event];
        return $datas;
    }

    public function addByEvent($event, $add) {
        $add = $this->repairIF($add);
        $datas = $this->getFromEvent($event);
        $datas[] = $add;
        $this->set($event, $datas);
    }

    public function del($key, $type, $num, $args = []){
        $datas = $this->getFromEvent($args["eventname"]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key][$type][$num]);
        $datas[$key][$type] = array_merge($datas[$key][$type]);
        $this->set($args["eventname"], $datas);
        return true;
    }

    public function updateContent($key, $type, $num, $new, $args = []){
        $datas = $this->getFromEvent($args["eventname"]);
        if(!isset($datas[$key]))return false;
        $datas[$key][$type][$num]["content"] = $new;
        $this->set($args["eventname"], $datas);
        return true;
    }

    public function remove($key, $args = []){
        $datas = $this->getFromEvent($args["eventname"]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key]);
        $datas = array_merge($datas);
        $this->set($args["eventname"], $datas);
        return true;
    }

    public function getReplaceDatas($datas){
        $result = parent::getReplaceDatas($datas);
        $event = $datas["event"];
        $eventname = $datas["eventname"];
        $variables = [];
        if(
            $eventname == "PlayerInteractEvent"
            or $eventname == "BlockBreakEvent"
            or $eventname == "BlockPlaceEvent"
        ){
            $block = $event->getBlock();
            $variables["block"] = new StringVariable("block", $block->__toString());
            $variables["block_name"] = new StringVariable("block_name", $block->getName());
            $variables["block_id"] = new NumberVariable("block_id", $block->getId());
            $variables["block_damage"] = new NumberVariable("block_damage", $block->getDamage());
            $variables["block_ids"] = new StringVariable("block_ids", $block->getId().":".$block->getDamage());
            $variables["block_pos"] = new StringVariable("block_pos", $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName());
            $variables["block_level"] = new StringVariable("block_level", $block->level->getFolderName());
            if($block instanceof SignPost) {
                $sign = $block->level->getTile($block);
                if($sign instanceof Sign) {
                    $variables["sign_lines"] = new ListVariable("sign_lines", $sign->getText());
                }
            }
        }
        if(
            $eventname == "PlayerChatEvent"
            or $eventname == "PlayerCommandPreprocessEvent"
        ){
            $variables["mes"] = new StringVariable("mes", $event->getMessage());
        }
        if($eventname == "PlayerCommandPreprocessEvent"){
            $args = explode(" ", $variables["mes"]->getValue());
            $variables["cmd"] = new StringVariable("cmd", array_shift($args));
            $variables["args"] = new ListVariable("args", $args);
        }
        if($eventname == "CraftItemEvent"){
            $inputs = $event->getInputs();
            $outputs = $event->getOutputs();
            $inputnames = [];
            $inputids = [];
            foreach ($inputs as $input) {
                $inputnames[] = $input->getName();
                $inputids[] = $input->getId().":".$input->getDamage();
            }
            $outputnames = [];
            $outputids = [];
            foreach ($outputs as $output) {
                $outputnames[] = $output->getName();
                $outputids[] = $output->getId().":".$output->getDamage();
            }
            $variables["input_name"] = new ListVariable("input_name", $inputnames);
            $variables["input_id"] = new ListVariable("input_id", $inputids);
            $variables["output_name"] = new ListVariable("output_name", $outputnames);
            $variables["output_id"] = new ListVariable("output_id", $outputids);
        }
        if($eventname == "EntityDamageEvent"){
            $entity = $event->getEntity();
            $variables["event_damage"] = new NumberVariable("event_damage", $event->getBaseDamage());
            $variables["evant_cause"] = new NumberVariable("evant_cause", $event->getCause());
            if($event instanceof EntityDamageByEntityEvent){
                $damager = $event->getDamager();
                if($damager instanceof Player){
                    $variables["attacker"] = new StringVariable("attacker", $damager->__toString());
                    $variables["attacker_name"] = new StringVariable("attacker_name", $damager->getName());
                    $variables["attacker_pos"] = new StringVariable("attacker_pos", $damager->x.",".$damager->y.",".$damager->z.",".$damager->level->getFolderName());
                    $variables["attacker_x"] = new NumberVariable("attacker_x", $damager->x);
                    $variables["attacker_y"] = new NumberVariable("attacker_y", $damager->y);
                    $variables["attacker_z"] = new NumberVariable("attacker_z", $damager->z);
                    $variables["attacker_level"] = new StringVariable("attacker_level", $damager->level->getFolderName());
                }
            }
        }
        if($eventname == "EntityLevelChangeEvent"){
            $variables["origin_level"] = new StringVariable("origin_level", $event->getOrigin()->getFolderName());
            $variables["target_level"] = new StringVariable("target_level", $event->getTarget()->getFolderName());
        }
        if($eventname == "TextPacketSendEvent") {
            $pk = $event->getPacket();
            $message = $pk->message;
            if($pk->needsTranslation) $message = $this->getServer()->getLanguage()->translateString($message, $pk->parameters);
            $variables["message"] = new StringVariable("message", $message);
        }
        return array_merge($result, $variables);
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\utils\Config;

use aieuo\ip\ifPlugin;
use aieuo\ip\ifAPI;

class ifManager extends ifAPI {

    const BLOCK = 0;
    const COMMAND = 1;
    const EVENT = 2;
    const CHAIN = 3;

	private $owner;
	private $config;

	public function __construct($owner, $type) {
		$this->owner = $owner;
        $this->config = new Config($owner->getDataFolder() . $type. ".yml", Config::YAML, []);
	}

	public function getOwner() {
		return $this->owner;
	}

    public function getServer() {
        return $this->getOwner()->getServer();
    }

    /**
     * @return Config
     */
    public function getConfig() {
        return $this->config;
    }

    /**
     * @param  string  $key
     * @param  array   $options
     * @return boolean
     */
    public function isAdded($key, $options = []) {
    	return $this->config->exists($key);
    }

    /**
     * @param  strign $key
     * @param  bool $args
     * @return bool | array
     */
    public function get($key, $args = []){
        if(!$this->isAdded($key))return false;
        $datas = $this->config->get($key);
        $datas = $this->repairIF($datas);
        return $datas;
    }

    /**
     * @return array
     */
    public function getAll() {
    	return $this->config->getAll();
    }

    /**
     * @param string $key
     * @param string $type
     * @param int $id
     * @param string $content
     * @param array  $args
     */
    public function add($key, $type, $id, $content, $args = []){
        $datas = [];
        if($this->isAdded($key))$datas = $this->get($key);
        $datas = $this->repairIF($datas);
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->config->set($key, $datas);
    }

    /**
     * @param string $key
     * @param array  $datas
     * @param array  $args
     */
    public function set($key, $datas = [], $args = []){
    	$this->config->set($key, $datas);
    }

    /**
     * @param  string $key
     * @param  string $type
     * @param  int $num
     * @return bool
     */
    public function del($key, $type, $num, $args = []){
        if(!$this->isAdded($key))return false;
        $datas = $this->get($key);
        unset($datas[$type][$num]);
        $datas[$type] = array_merge($datas[$type]);
        $this->config->set($key, $datas);
        return true;
    }

    /**
     * @param  string $key
     * @param  string $type
     * @param  int $num
     * @return bool
     */
    public function updateContent($key, $type, $num, $new, $args = []){
        if(!$this->isAdded($key))return false;
        $datas = $this->get($key);
        $datas[$type][$num]["content"] = $new;
        $this->config->set($key, $datas);
        return true;
    }

    /**
     * @param  string $key
     */
    public function remove($key) {
    	$this->config->remove($key);
    }

	public function save() {
		$this->config->save();
	}

    /**
     * @param  array $datas
     * @return array
     */
    public function repairIF($datas){
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        return $datas;
    }

    public function getReplaceDatas($datas) {
        return parent::getReplaceDatas($datas);
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddEffect extends Process {

	protected $id = self::ADD_EFFECT;
    protected $name = "ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’ä¸Žãˆã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã«idãŒÂ§7<id>Â§fã§å¼·ã•ãŒÂ§7<power>Â§fã®ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’Â§7<time>Â§fç§’é–“ä¸Žãˆã‚‹";

	public function getMessage() {
		$effect = $this->getEffect();
		if(!($effect instanceof EffectInstance)) return false;
		return "idãŒ".$effect->getId()."ã§å¼·ã•ãŒ".$effect->getAmplifier()."ã®ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’".($effect->getDuration() * 20)."ç§’é–“ä¸Žãˆã‚‹";
	}

	public function getEffect() {
		return $this->getValues();
	}

	public function setEffect(EffectInstance $effect) {
		$this->setValues($effect);
	}

	public function parse(string $content) {
        $args = explode(",", $content);
        if(!isset($args[1]) or (int)$args[1] <= 0) $args[1] = 1;
        if(!isset($args[2]) or (float)$args[2] <= 0) $args[2] = 30;
		$effect = Effect::getEffectByName($args[0]);
        if($effect === null) $effect = Effect::getEffect((int)$args[0]);
        if($effect === null) return null;
		return new EffectInstance($effect, (float)$args[2] * 20, (int)$args[1], true);
	}

	public function execute() {
		$player = $this->getPlayer();
		$effect = $this->getEffect();
		if(!($effect instanceof EffectInstance))
		{
			if($effect === false) $player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			if($effect === null) $player->sendMessage("Â§c[".$this->getName()."] ã‚¨ãƒ•ã‚§ã‚¯ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
			return;
		}
		$player->addEffect($effect);
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$effect = $this->parse($default);
		$id = $default;
		$power = "";
		$time = "";
		if($effect instanceof EffectInstance)
		{
			$id = $effect->getId();
			$power = $effect->getAmplifier();
			$time = $effect->getDuration() * 20;
		}
		elseif($default !== "")
		{
			if($effect === false)$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
			if($effect === null)$mes .= "Â§cã‚¨ãƒ•ã‚§ã‚¯ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<id>Â§f ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã®åå‰ã‹idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1", $id),
                Elements::getInput("\nÂ§7<power>Â§f ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã®å¼·ã•ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $power),
                Elements::getInput("\nÂ§7<time>Â§f ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’ä¸Žãˆã‚‹æ™‚é–“ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $time),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$effect_str = $datas[1].",".$datas[2].",".$datas[3];
    	if($datas[1] === "" or $datas[2] === "" or $datas[3] === "") $status = null;
    	return ["status" => $status, "contents" => $effect_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddEnchantment extends Process {

	protected $id = self::ADD_ENCHANTMENT;
    protected $name = "æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’è¿½åŠ ã™ã‚‹";
    protected $description = "æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«idãŒÂ§7<id>Â§fã§å¼·ã•ãŒÂ§7<power>Â§fã®ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’è¿½åŠ ã™ã‚‹";

	public function getMessage() {
		$enchant = $this->getEnchantment();
		if(!($enchant instanceof EnchantmentInstance)) return false;
		return "æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«idãŒ".$enchant->getId()."ã§".$enchant->getLevel()."ãƒ¬ãƒ™ãƒ«ã®ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’è¿½åŠ ã™ã‚‹";
	}

	public function getEnchantment() {
		return $this->getValues();
	}

	public function setEnchantment(EnchantmentInstance $enchant) {
		$this->setValues($enchant);
	}

	public function parse(string $content) {
        $args = explode(",", $content);
        if(!isset($args[1]) or (int)$args[1] <= 0) $args[1] = 1;
        if(is_numeric($args[0])) {
            $enchantment = Enchantment::getEnchantment((int)$args[0]);
        } else {
            $enchantment = Enchantment::getEnchantmentByName($args[0]);
        }
        if(!($enchantment instanceof Enchantment)) return null;
        return new EnchantmentInstance($enchantment, (int)$args[1]);
	}

	public function execute() {
		$player = $this->getPlayer();
		$enchant = $this->getEnchantment();
		if(!($enchant instanceof EnchantmentInstance)) {
			if($enchant === false) $player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			if($enchant === null) $player->sendMessage("Â§c[".$this->getName()."] ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
			return;
		}
		$item = $player->getInventory()->getItemInHand();
        $item->addEnchantment($enchant);
		$player->getInventory()->setItemInHand($item);
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$enchant = $this->parse($default);
		$id = $default;
		$power = "";
		if($enchant instanceof EnchantmentInstance) {
			$id = $enchant->getId();
			$power = $enchant->getLevel();
		} elseif($default !== "") {
			if($enchant === false) $mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
			if($enchant === null) $mes .= "Â§cã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<id>Â§f ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã®åå‰ã‹idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1", $id),
                Elements::getInput("\nÂ§7<power>Â§f ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã®ãƒ¬ãƒ™ãƒ«ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $power),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$enchant_str = $datas[1].",".$datas[2];
    	if($datas[1] === "" or $datas[2] === "") $status = null;
    	return ["status" => $status, "contents" => $enchant_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddItem extends TypeItem {

	protected $id = self::ADD_ITEM;
	protected $name = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã™ã‚‹";
	protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«idãŒÂ§7<id>Â§fã®Â§7<name>Â§fã¨ã„ã†åå‰ã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§fè¿½åŠ ã™ã‚‹";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«(".$item->getId().":".$item->getDamage().",".$item->getName().")"."ã‚’".$item->getCount()."å€‹è¿½åŠ ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$item = $this->getItem();
		if(!($item instanceof Item)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$player->getInventory()->addItem($item);
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddMoney extends TypeMoney {

	protected $id = self::ADDMONEY;
    protected $name = "æ‰€æŒé‡‘ã‚’å¢—ã‚„ã™";
    protected $description = "æ‰€æŒé‡‘ã‚’Â§7<amount>Â§få¢—ã‚„ã™";

	public function getMessage() {
		return "æ‰€æŒé‡‘ã‚’".$this->getAmount()."å¢—ã‚„ã™";
	}

	public function execute() {
		$player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if($economy === null) {
            $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            return;
        }
        $economy->addMoney($player->getName(), $this->getAmount());
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddVariable extends Process {

	protected $id = self::ADD_VARIABLE;
    protected $name = "å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹";
    protected $description = "Â§7<name>Â§fã¨ã„ã†åå‰ã§Â§7<value>Â§fã¨ã„ã†å€¤ã®å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹";

	public function getMessage() {
		$variable = $this->getVariable();
		if($variable === false) return false;
		return $variable->getName()."ã¨ã„ã†åå‰ã§".$variable->getValue()."ã¨ã„ã†å€¤ã®å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹";
	}

	public function getVariable() {
		return $this->getValues();
	}

	public function setVariable(Variable $variable) {
		$this->setValues($variable);
	}

	public function parse(string $content) {
        $datas = explode(";", $content);
        if(!isset($datas[1]) or $datas[1] === "") return false;
        $helper = ifPlugin::getInstance()->getVariableHelper();
        $value = $helper->changeType($datas[1]);
        return Variable::create($datas[0], $value, $helper->getType($datas[1]));
	}

	public function execute() {
		$player = $this->getPlayer();
		$variable = $this->getVariable();
		if($variable === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
        ifPlugin::getInstance()->getVariableHelper()->add($variable);
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$var = $this->parse($default);
		$name = $default;
		$value = "";
		if($var instanceof Variable) {
			$name = $var->getName();
			$value = $var->getValue();
			if(is_numeric($value) and $var->getType() === Variable::STRING) {
				$value = "(str)".$value;
			} elseif(!is_numeric($value) and $var->getType() === Variable::NUMBER) {
				$value = "(num)".$value;
			}
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f å¤‰æ•°ã®åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $name),
                Elements::getInput("\nÂ§7<value>Â§f å¤‰æ•°ã®å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1000", $value),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$var_str = $datas[1].";".$datas[2];
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$var = $this->parse($var_str);
	    	if($var === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $var_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\event\entity\EntityDamageEvent;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Attack extends Process {

	protected $id = self::ATTACK;
    protected $name = "ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’ä¸Žãˆã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’Â§7<damage>Â§fä¸Žãˆã‚‹";

	public function getMessage() {
		$damage = $this->getDamage();
		if($damage === false) return false;
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã«".$damage."ãƒ€ãƒ¡ãƒ¼ã‚¸ä¸Žãˆã‚‹";
	}

	public function getDamage() {
		return $this->getValues();
	}

	public function setDamage(float $damage) {
		$this->setValues($damage);
	}

	public function parse(string $content) {
		$damage = (float)$content;
		if($damage <= 0) return false;
		return $damage;
	}

	public function execute() {
		$player = $this->getPlayer();
		$damage = $this->getDamage();
		if($damage === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ”»æ’ƒåŠ›ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„");
			return;
		}
		$event = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
		$player->attack($event);
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$damage = $this->parse($default);
		if($damage === false) {
			if($default !== "") $mes .= "Â§cæ”»æ’ƒåŠ›ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„Â§f";
			$damage = $default;
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<damage>Â§f æ”»æ’ƒåŠ›ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $damage),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$damage = $this->parse($datas[1]);
	    	if($damage === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class BroadcastMessage extends TypeMessage {

	protected $id = self::BROADCASTMESSAGE;
	protected $name = "å…¨å“¡ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
	protected $description = "å…¨å“¡ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "å…¨å“¡ã«".$message."ã¨é€ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
        Server::getInstance()->broadcastMessage($this->getSendMessage());
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;
use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Calculation extends Process {

	protected $id = self::CALCULATION;
    protected $name = "äºŒã¤ã®å€¤ã‚’è¨ˆç®—ã™ã‚‹";
    protected $description = "Â§7<value1>Â§fã¨Â§7<value2>Â§fã‚’è¨ˆç®—Â§7<opefator>Â§rã—ãŸçµæžœã‚’{result}ã«å…¥ã‚Œã‚‹";

	const ERROR = -1;
	const ADDITION = 0;
	const SUBTRACTION = 1;
	const MULTIPLICATION = 2;
	const DIVISION = 3;
	const MODULO = 4;

	public function getMessage() {
		if($this->getValues() === false) return false;
		$variable1 = $this->getValue1();
		$variable2 = $this->getValue2();
		for($i = 1; $i <= 2; $i ++) {
			${"value".$i} = ${"variable".$i}->getValue();

			if(${"variable".$i} instanceof StringVariable and is_numeric(${"value".$i})) {
				${"value".$i} = "(str)".${"value".$i};
			} elseif(${"variable".$i} instanceof NumberVariable and !is_numeric(${"value".$i})) {
				${"value".$i} = "(num)".${"value".$i};
			} elseif(${"variable".$i} instanceof ListVariable) {
				${"value".$i} = "(list)".${"variable".$i}->toStringVariable()->getValue();
			}
		}
		$operator = $this->getOperator();
        switch ($operator){
            case self::ADDITION:
            	$mes = $value1."ã¨".$value2."ã‚’è¶³ã™";
                break;
            case self::SUBTRACTION:
            	$mes = $value1."ã‹ã‚‰".$value2."ã‚’å¼•ã";
                break;
            case self::MULTIPLICATION:
            	$mes = $value1."ã¨".$value2."ã‚’æŽ›ã‘ã‚‹";
                break;
            case self::DIVISION:
            	$mes = $value1."ã‚’".$value2."ã§å‰²ã‚‹";
                break;
            case self::MODULO:
            	$mes = $value1."ã‚’".$value2."ã§å‰²ã£ãŸä½™ã‚Šã‚’å‡ºã™";
                break;
            default:
                return false;
        }
        return $mes;
	}

	public function getValue1() {
		return $this->getValues()[0];
	}

	public function getValue2() {
		return $this->getValues()[1];
	}

	public function getOperator() {
		return $this->getValues()[2];
	}

	public function getAssignName() {
		return $this->getValues()[3];
	}

	public function setNumbers(Variable $value1, Variable $value2, int $ope, string $assign = "result") {
		$this->setValues([$value1, $value2, $ope, $assign]);
	}

	public function parse(string $numbers) {
        if(!preg_match("/\s*(.+)\s*\[ope:([0-9])\]\s*(.+)\s*;\s*([^;]*)\s*$/", $numbers, $matches)) return false;
        $helper = ifPlugin::getInstance()->getVariableHelper();
        $operator = (int)$matches[2];
        $value1 = $matches[1];
        $value2 = $matches[3];
        $assign = $matches[4] === "" ? "result" : $matches[4];
        $type1 = $helper->getType($value1);
        $value1 = $helper->changeType($value1);
        $var1 = Variable::create("value1", $value1, $type1);
        $type2 = $helper->getType($value2);
        $value2 = $helper->changeType($value2);
        $var2 = Variable::create("value2", $value2, $type2);
        return [$var1, $var2, $operator, $assign];
	}

	public function execute() {
		if($this->getValues() === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$player = $this->getPlayer();
		$variable1 = $this->getValue1();
		$variable2 = $this->getValue2();
		$operator = $this->getOperator();
		$name = $this->getAssignName();
        switch ($operator){
            case self::ADDITION:
                $result = $variable1->Addition($variable2, $name);
                break;
            case self::SUBTRACTION:
                $result = $variable1->Subtraction($variable2, $name);
                break;
            case self::MULTIPLICATION:
                $result = $variable1->Multiplication($variable2, $name);
                break;
            case self::DIVISION:
                $result = $variable1->Division($variable2, $name);
                break;
            case self::MODULO:
                $result = $variable1->Modulo($variable2, $name);
                break;
            default:
                $player->sendMessage("Â§c[".$this->getName()."] ãã®çµ„ã¿åˆã‚ã›ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“");
                return;
        }
        if($result->getName() == "ERROR") {
        	$player->sendMessage("Â§c[".$this->getName()."] ".$result->getValue());
        	return;
        }
        ifPlugin::getInstance()->getVariableHelper()->add($result);
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$values = $this->parse($default);
		$value0 = $default;
		$value1 = "";
		$operator = self::ADDITION;
		$name = "";
		if($values !== false) {
			for($i = 0; $i <= 1; $i ++) {
				${"value".$i} = $values[$i]->getValue();

				if($values[$i] instanceof StringVariable and is_numeric(${"value".$i})) {
					${"value".$i} = "(str)".${"value".$i};
				} elseif($values[$i] instanceof NumberVariable and !is_numeric(${"value".$i})) {
					${"value".$i} = "(num)".${"value".$i};
				} elseif($values[$i] instanceof ListVariable) {
					${"value".$i} = "(list)".$values[$i]->toStringVariable()->getValue();
				}
			}
			$operator = $values[2];
			$name = $values[3];
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<value1>Â§f ä¸€ã¤ç›®ã®å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 100", $value0),
                Elements::getDropdown("\nÂ§7<operator>Â§f é¸ã‚“ã§ãã ã•ã„", [
                	"ä¸€ã¤ç›®ã®å€¤ã¨äºŒã¤ç›®ã®å€¤ã‚’è¶³ã™ (value1 + value2)",
                	"ä¸€ã¤ç›®ã®å€¤ã¨äºŒã¤ç›®ã®å€¤ã‚’å¼•ã (value1 - value2)",
                	"ä¸€ã¤ç›®ã®å€¤ã¨äºŒã¤ç›®ã®å€¤ã‚’æŽ›ã‘ã‚‹ (value1 * value2)",
                	"ä¸€ã¤ç›®ã®å€¤ã‚’äºŒã¤ç›®ã§å€¤ã‚’å‰²ã‚‹ (value1 / value2)",
                	"ä¸€ã¤ç›®ã®å€¤ã‚’äºŒã¤ç›®ã§å€¤ã‚’å‰²ã£ãŸä½™ã‚Š (value1 % value2)",
                ], $operator),
                Elements::getInput("\nÂ§7<value2>Â§f äºŒã¤ç›®ã®å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 50", $value1),
                Elements::getInput("\nÂ§7<result>Â§f çµæžœã‚’ä»£å…¥ã™ã‚‹å¤‰æ•°ã®åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(ç©ºç™½ãªã‚‰result)", "ä¾‹) aieuo", $name),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$values_str = $datas[1]."[ope:".$datas[2]."]".$datas[3].";".$datas[4];
    	if($datas[1] === "" or $datas[2] === "" or $datas[3] === "") {
    		$status = null;
    	} else {
	    	$values = $this->parse($values_str);
	    	if($values === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $values_str, "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Command extends TypeCommand {

	protected $id = self::COMMAND;
	protected $name = "ã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã™ã‚‹";
	protected $description = "ã‚³ãƒžãƒ³ãƒ‰Â§7<command>Â§fã‚’å®Ÿè¡Œã™ã‚‹";

	public function getMessage() {
		$command = $this->getCommand();
		return "/".$command." ã‚’å®Ÿè¡Œã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
        Server::getInstance()->dispatchCommand($player, $this->getCommand());
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\command\ConsoleCommandSender;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class CommandConsole extends TypeCommand {

	protected $id = self::COMMAND_CONSOLE;
	protected $name = "ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã™ã‚‹";
	protected $description = "ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã‚³ãƒžãƒ³ãƒ‰Â§7<command>Â§fã‚’å®Ÿè¡Œã™ã‚‹";

	public function getMessage() {
		$command = $this->getCommand();
		return "ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰/".$command." ã‚’å®Ÿè¡Œã™ã‚‹";
	}

	public function execute() {
        Server::getInstance()->dispatchCommand(new ConsoleCommandSender, $this->getCommand());
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Cooperation extends Process {

	protected $id = self::COOPERATION;
    protected $name = "ã»ã‹ã®IFã¨é€£æºã™ã‚‹";
    protected $description = "Â§7<name>Â§fã¨ã„ã†åå‰ã®IFã‚’å®Ÿè¡Œã™ã‚‹";

	public function getMessage() {
		$name = $this->getCooperationName();
		return $name."ã‚’å®Ÿè¡Œã™ã‚‹";
	}

	public function getCooperationName() {
		return $this->getValues();
	}

	public function setCooperationName(string $name) {
		$this->setValues($name);
	}

	public function execute() {
		$player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if(!$manager->isAdded($this->getCooperationName())) {
        	$player->sendMessage("Â§c[".$this->getName()."] ãã®åå‰ã®ç‰©ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
        	return;
        }
        $datas = $manager->get($this->getCooperationName());
        $manager->executeIfMatchCondition($player,
            $datas["if"],
            $datas["match"],
            $datas["else"],
            ["player" => $player]
        );
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        if($default !== "" and !$manager->isAdded($default)) $mes .= "Â§eãã®åå‰ã®IFã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“";
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class CooperationRepeat extends Process {

	protected $id = self::COOPERATION_REPEAT;
    protected $name = "ã»ã‹ã®IFæŒ‡å®šã—ãŸå›žæ•°å®Ÿè¡Œã™ã‚‹";
    protected $description = "Â§7<name>Â§fã¨ã„ã†åå‰ã®IFã‚’Â§7<count>Â§få›žå®Ÿè¡Œã™ã‚‹";

	public function getMessage() {
		$name = $this->getCooperationName();
		$count = $this->getCount();
		return $name."ã‚’".$count."å›žå®Ÿè¡Œã™ã‚‹";
	}

	public function getCooperationName() {
		return $this->getValues()[0];
	}

	public function getCount() {
		return $this->getValues()[1];
	}

	public function setNames(string $name, int $count) {
		$this->setValues([$name, $count]);
	}

	public function parse(string $content) {
		$datas = explode(";", $content);
		if(!isset($datas[1])) return false;
		$count = array_pop($datas);
		$name = implode(";", $datas);
        return [$name, $count];
	}

	public function execute() {
		$player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if(!$manager->isAdded($this->getCooperationName())) {
        	$player->sendMessage("Â§c[".$this->getName()."] ãã®åå‰ã®ç‰©ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
        	return;
        }
        $datas = $manager->get($this->getCooperationName());
        $count = $this->getCount();
        for($i = 0; $i < $count; $i ++) {
	        $manager->executeIfMatchCondition($player,
	            $datas["if"],
	            $datas["match"],
	            $datas["else"],
	            [
	            	"player" => $player,
	            	"count" => $i
	            ]
	        );
	    }
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        $names = $this->parse($default);
        $name = $default;
        $count = "";
        if($names === false and $default !== "") {
        	$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
        } else {
        	$name = $names[0];
        	$count = $names[1];
        }
        if($default !== "" and !$manager->isAdded($name)) $mes .= "Â§eãã®åå‰ã®IFã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“";
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $name),
                Elements::getInput("\nÂ§7<count>Â§f å®Ÿè¡Œã™ã‚‹å›žæ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $count),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$status = true;
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$names = $this->parse($datas[1].";".$datas[2]);
	    	if($names === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1].";".$datas[2], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\task\DelayedCommandTask;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class DelayedCommand extends Process {

	protected $id = self::DELAYED_COMMAND;
    protected $name = "é…ã‚Œã¦ã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã™ã‚‹";
    protected $description = "Â§7<time>Â§fç§’é…ã‚Œã¦ã‚³ãƒžãƒ³ãƒ‰Â§7<command>Â§fã‚’å®Ÿè¡Œã™ã‚‹";

	public function getMessage() {
		if($this->getValues() === false) return false;
		$command = $this->getCommand();
		$time = $this->getTime();
		return round($time / 20, 2)."ç§’é…ã‚Œã¦/".$command." ã‚’å®Ÿè¡Œã™ã‚‹";
	}

	public function getTime() {
		return $this->getValues()[1];
	}

	public function getCommand() {
		return $this->getValues()[0];
	}

	public function setCommands(string $command, int $time) {
		$this->setValues($command, $time);
	}

	public function parse(string $commands) {
	    if(!preg_match("/([0-9]+),(.+)/", $commands, $matches)) return false;
	    return [$matches[2], (int)$matches[1]];
	}

	public function execute() {
		$player = $this->getPlayer();
		if($this->getValues() === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$time = $this->getTime();
		$command = $this->getCommand();
        ifPlugin::getInstance()->getScheduler()->scheduleDelayedTask(new DelayedCommandTask($player, $command), $time*20);
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$commands = $this->parse($default);
		$command = $default;
		$time = "";
		if($commands !== false) {
			$command = $commands[0];
			$time = $commands[1];
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<command>Â§f å®Ÿè¡Œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) help", $command),
                Elements::getInput("\nÂ§7<time>Â§f é…ã‚‰ã›ã‚‹tickæ•°(20tickã§1ç§’)ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 10", $time),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$value = $this->parse($datas[2].",".$datas[1]);
	    	if($value === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[2].",".$datas[1], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class DeleteVariable extends Process {

	protected $id = self::DELETE_VARIABLE;
    protected $name = "å¤‰æ•°ã‚’å‰Šé™¤ã™ã‚‹";
    protected $description = "Â§7<name>Â§fã¨ã„ã†åå‰ã®å¤‰æ•°ã‚’å‰Šé™¤ã™ã‚‹";

	public function getMessage() {
		return $this->getVariableName()."ã¨ã„ã†åå‰ã®å¤‰æ•°ã‚’å‰Šé™¤ã™ã‚‹";
	}

	public function getVariableName() {
		return $this->getValues();
	}

	public function setVariableName(string $variable) {
		$this->setValues($variable);
	}

	public function execute() {
		$player = $this->getPlayer();
        ifPlugin::getInstance()->getVariableHelper()->del($this->getVariableName());
	}


	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f å¤‰æ•°ã®åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

class DoNothing extends Process {

	protected $id = self::DO_NOTHING;
	protected $name = "ä½•ã‚‚ã—ãªã„";
	protected $description = "ä½•ã‚‚ã—ãªã„";

	public function getMessage() {
		return "ä½•ã‚‚ã—ãªã„";
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\event;
use pocketmine\event\Cancellable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class EventCancel extends Process {

	protected $id = self::EVENT_CANCEL;
	protected $name = "ã‚¤ãƒ™ãƒ³ãƒˆã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";
	protected $description = "ã‚¤ãƒ™ãƒ³ãƒˆã‚’ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";

	public function getMessage() {
		return "ã‚¤ãƒ™ãƒ³ãƒˆã‚’ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";
	}

	public function getEvent() {
		return $this->getValues();
	}

	public function setEvent(Event $effect) {
		$this->setValues($effect);
	}

	public function execute() {
		$event = $this->getEvent();
		if($event instanceof Cancellable) $event->setCancelled();
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\ifPlugin;

use aieuo\ip\variable\Variable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class ExecuteOtherPlayer extends Process {

	protected $id = self::EXECUTE_OTHER_PLAYER;
    protected $name = "ã»ã‹ã®ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã¨ã—ã¦IFã‚’å®Ÿè¡Œã™ã‚‹";
    protected $description = "Â§7<player>Â§fã«Â§7<name>Â§fã¨ã„ã†åå‰ã®IFã‚’å®Ÿè¡Œã•ã›ã‚‹";

	public function getMessage() {
		$cname = $this->getCooperationName();
		$pname = $this->getPlayerName();
		return $cname."ã‚’".$pname."ã«å®Ÿè¡Œã•ã›ã‚‹";
	}

	public function getCooperationName() {
		return $this->getValues()[0];
	}

	public function getPlayerName() {
		return $this->getValues()[1];
	}

	public function setNames(string $name, string $playerName) {
		$this->setValues([$name, $playerName]);
	}

	public function parse(string $content) {
		$datas = explode(";", $content);
		if(!isset($datas[1])) return false;
		$pname = array_pop($datas);
		$cname = implode(";", $datas);
        return [$cname, $pname];
	}

	public function execute() {
		$player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if(!$manager->isAdded($this->getCooperationName())) {
        	$player->sendMessage("Â§c[".$this->getName()."] ãã®åå‰ã®ç‰©ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
        	return;
        }
        $playerName = $this->getPlayerName();
        $target = Server::getInstance()->getPlayer($playerName);
        if($target === null) {
        	$player->sendMessage("Â§c[".$this->getName()."] ".$playerName."ã¯ä»Šã‚µãƒ¼ãƒãƒ¼ã«ã„ã¾ã›ã‚“");
        	return;
        }
        $datas = $manager->get($this->getCooperationName());
        $manager->executeIfMatchCondition($target,
            $datas["if"],
            $datas["match"],
            $datas["else"],
            [
            	"player" => $target,
            	"origin" => $player
            ]
        );
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        $names = $this->parse($default);
        $cname = $default;
        $pname = "";
        if($names === false and $default !== "") {
        	$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
        } else {
        	$cname = $names[0];
        	$pname = $names[1];
        }
        if($default !== "" and !$manager->isAdded($name)) $mes .= "Â§eãã®åå‰ã®IFã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“Â§f";
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f å®Ÿè¡Œã™ã‚‹IFã®åå‰ã‚’", "ä¾‹) aieuo", $cname),
                Elements::getInput("\nÂ§7<player>Â§f ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®åå‰ã‚’", "ä¾‹) aiueo421", $pname),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$status = true;
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$names = $this->parse($datas[1].";".$datas[2]);
	    	if($names === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1].";".$datas[2], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\task\KickTask;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Kick extends Process {

	protected $id = self::KICK;
    protected $name = "ã‚­ãƒƒã‚¯ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’Â§7<reason>Â§fã§ã‚­ãƒƒã‚¯ã™ã‚‹";

	public function getMessage() {
		$reason = $this->getReason();
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’".$reason."ã§ã‚­ãƒƒã‚¯ã™ã‚‹";
	}

	public function getReason() {
		return $this->getValues();
	}

	public function setReason(string $reason) {
		$this->setValues($reason);
	}

	public function execute() {
		$player = $this->getPlayer();
		$reason = $this->getReason();
        ifPlugin::getInstance()->getScheduler()->scheduleDelayedTask(new KickTask($player, $reason), 5);
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<reason>Â§f ç†ç”±ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) æ‚ªã„ã“ã¨ã‚’ã—ãŸã‹ã‚‰", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\math\Vector3;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Motion extends TypePosition {

    protected $id = self::MOTION;
    protected $name = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‹ã™";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’Â§7<x> <y> <z>Â§fãƒ–ãƒ­ãƒƒã‚¯å‹•ã‹ã™";

    public function getMessage() {
        $pos = $this->getPosition();
        if($pos === false) return false;
        return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’".$pos->x.",".$pos->y.",".$pos->z."ãƒ–ãƒ­ãƒƒã‚¯å‹•ã‹ã™";
    }

    public function execute() {
        $player = $this->getPlayer();
        $pos = $this->getPosition();
        if(!($pos instanceof Vector3)) {
            $player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
            return;
        }
        $player->setMotion($pos);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $pos = $this->parse($default);
        $x = $default;
        $y = "";
        $z = "";
        if($pos instanceof Vector3) {
            $x = $pos->x;
            $y = $pos->y;
            $z = $pos->z;
        } elseif($default !== "") {
            $mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<x>Â§f xè»¸æ–¹å‘ã«å‹•ã‹ã™å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1", $x),
                Elements::getInput("\nÂ§7<y>Â§f yè»¸æ–¹å‘ã«å‹•ã‹ã™å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 10", $y),
                Elements::getInput("\nÂ§7<z>Â§f zè»¸æ–¹å‘ã«å‹•ã‹ã™å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 100", $z),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if($datas[1] === "" and $datas[2] === "" and $datas[3] === "") {
            $status = null;
        } else {
            $pos = $this->parse($datas[1].",".$datas[2].",".$datas[3]);
            if($pos === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1].",".$datas[2].",".$datas[3], "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Player;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Process implements ProcessIds {

    /** @var Player */
    private $player;

    /** @var array */
    private $values = [];

    /** @var int */
    protected $id;

    /** @var string */
    protected $name = "";

    /** @var string */
    protected $description = "";

    public function __construct($player = null) {
        $this->player = $player;
    }

    public static function get($id) {
        return ProcessFactory::get($id);
    }

    public function getId() {
        return $this->id;
    }

    public function getName() {
        return $this->name;
    }

    public function getDescription() {
        return $this->description;
    }

    public function parse(string $str) {
        return $str;
    }

    public function setPlayer(Player $player) : self {
        $this->player = $player;
        return $this;
    }

    public function getPlayer() : Player {
        return $this->player;
    }

    public function setValues($values) : self {
        $this->values = $values;
        return $this;
    }

    public function getValues() {
        return $this->values;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        if($mes !== "") $mes = "\n".$mes;
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().$mes),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        return ["status" => true, "contents" => "", "delete" => $datas[1], "cancel" => $datas[2]];
    }

    public function execute() {
    }
}<?php

namespace aieuo\ip\processes;

class ProcessFactory {
	private static $list = [];

	public static function init() {
		self::register(new DoNothing());
		self::register(new SendMessage());
		self::register(new SendTip());
		self::register(new SendTitle());
		self::register(new BroadcastMessage());
		self::register(new SendMessageToOp());
		self::register(new SendVoiceMessage());
		self::register(new Command());
		self::register(new CommandConsole());
		self::register(new DelayedCommand());
		self::register(new AddMoney());
		self::register(new TakeMoney());
		self::register(new Teleport());
		self::register(new Motion());
		self::register(new Calculation());
		self::register(new AddVariable());
		self::register(new DeleteVariable());
		self::register(new AddItem());
		self::register(new RemoveItem());
		self::register(new SetItem());
		self::register(new SetImmobile());
		self::register(new UnSetImmobile());
		self::register(new AddEnchantment());
		self::register(new AddEffect());
		self::register(new SetNametag());
		self::register(new SetSleeping());
		self::register(new SetSitting());
		self::register(new EventCancel());
		self::register(new SetGamemode());
		self::register(new Cooperation());
		self::register(new CooperationRepeat());
		self::register(new ExecuteOtherPlayer());
		self::register(new SetBlocks());
		self::register(new SaveDatas());
		self::register(new SetHealth());
		self::register(new SetMaxHealth());
		self::register(new Attack());
		self::register(new Kick());
	}

	/**
	 * @param  int $id
	 * @return Process
	 */
	public static function get($id) {
		if(isset(self::$list[$id])) {
			return clone self::$list[$id];
		}
		return new Process();
	}

	public static function getAll() {
		return self::$list;
	}

	/**
	 * @param  Condition $process
	 */
	public static function register(Process $process) {
		self::$list[$process->getId()] = clone $process;
	}
}<?php

namespace aieuo\ip\processes;

interface ProcessIds {
    const COMMAND = 100;
    const SENDMESSAGE = 101;
    const SENDTIP = 102;
    const TELEPORT = 103;
    const BROADCASTMESSAGE = 104;
    const COMMAND_CONSOLE = 105;
    const DO_NOTHING = 106;
    const ADD_ITEM = 107;
    const REMOVE_ITEM = 108;
    const SET_IMMOBILE = 109;
    const UNSET_IMMOBILE = 110;
    const SET_HEALTH = 111;
    const SET_MAXHEALTH = 112;
    const SET_GAMEMODE = 113;
    const SET_NAMETAG = 114;
    const ADD_ENCHANTMENT = 115;
    const ADD_EFFECT = 116;
    const EVENT_CANCELL = 117;
    const SENDMESSAGE_TO_OP = 118;
    const SET_SLEEPING = 119;
    const SET_SITTING = 120;
    const ATTACK = 121;
    const KICK = 122;
    const SENDVOICEMESSAGE = 123;
    const SENDTITLE = 124;
    const MOTION = 125;
    const DELAYED_COMMAND = 126;
    const CALCULATION = 127;
    const ADD_VARIABLE = 128;
    const SET_SCALE = 129;
    const EVENT_CANCEL = 130;
    const SET_ITEM = 131;
    const SAVE_DATAS = 132;
    const ADDMONEY = 133;
    const TAKEMONEY = 134;
    const COOPERATION = 135;
    const DELETE_VARIABLE = 136;
    const SET_BLOCKS = 137;
    const COOPERATION_REPEAT = 138;
    const EXECUTE_OTHER_PLAYER = 139;
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class RemoveItem extends TypeItem {

    protected $id = self::REMOVE_ITEM;
    protected $name = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ ã‚’å‰Šé™¤ã™ã‚‹";
    protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰idãŒÂ§7<id>Â§fã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§få‰Šé™¤ã™ã‚‹";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰(".$item->getId().":".$item->getDamage().",".$item->getName().")"."ã‚’".$item->getCount()."å€‹å‰Šé™¤ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$item = $this->getItem();
        if($item->getCount() > 0) {
            $player->getInventory()->removeItem($item);
            return;
        }
        $count = 0;
        foreach ($player->getInventory()->getContents() as $item1) {
            if($item1->getId() == $item->getId() and $item1->getDamage() == $item->getDamage()) {
                $count += $item1->getCount();
            }
        }
        $item->setCount($count);
        if($item->getCount() > 0) {
            $player->getInventory()->removeItem($item);
        }
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		$name = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			$name = $item->hasCustomName() ? $item->getName() : "";
			if($count === 0) $mes .= "Â§eæŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ã‚’ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰ã™ã¹ã¦å‰Šé™¤ã—ã¾ã™Â§f";
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“ (idã¯0ä»¥ä¸Šã®æ•°å­—ã§å…¥åŠ›ã—ã¦ãã ã•ã„)Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<id>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getInput("\nÂ§7<count>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(å…¨ã¦æ¶ˆã™å ´åˆã¯0ã‚’å…¥åŠ›ã™ã‚‹ã‹ç©ºç™½ã«ã—ã¦ãã ã•ã„)", "ä¾‹) 5", $count),
                Elements::getInput("\nÂ§7<name>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã«ä»˜ã‘ãŸã„åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(ç©ºç™½ãªã‚‰ãã®ã¾ã¾ã®åå‰ã§ã™)", "ä¾‹) aieuo", $name),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;

class SaveDatas extends Process {

    protected $id = self::SAVE_DATAS;
    protected $name = "ãƒ‡ãƒ¼ã‚¿ã‚’ã‚»ãƒ¼ãƒ–ã™ã‚‹";
    protected $description = "ãƒ‡ãƒ¼ã‚¿ã‚’ã‚»ãƒ¼ãƒ–ã™ã‚‹";

	public function getMessage() {
		return "ãƒ‡ãƒ¼ã‚¿ã‚’ã‚»ãƒ¼ãƒ–ã™ã‚‹";
	}

	public function execute() {
        ifPlugin::getInstance()->getBlockManager()->save();
        ifPlugin::getInstance()->getCommandManager()->save();
        ifPlugin::getInstance()->getEventManager()->save();
        ifPlugin::getInstance()->getChainManager()->save();
        ifPlugin::getInstance()->getVariableHelper()->save();
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SendMessage extends TypeMessage {

    protected $id = self::SENDMESSAGE;
    protected $name = "ãƒãƒ£ãƒƒãƒˆæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
    protected $description = "ãƒãƒ£ãƒƒãƒˆæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "ãƒãƒ£ãƒƒãƒˆæ¬„ã«".$message."ã¨é€ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$player->sendMessage($this->getSendMessage());
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SendMessageToOp extends TypeMessage {

    protected $id = self::SENDMESSAGE_TO_OP;
    protected $name = "opã ã‘ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
    protected $description = "opã ã‘ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "opã ã‘ã«".$message."ã¨é€ã‚‹";
	}

	public function execute() {
    	$players = Server::getInstance()->getOnlinePlayers();
    	foreach ($players as $player) {
    		if($player->isOp()){
    			$player->sendMessage($this->getSendMessage());
    		}
    	}
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SendTip extends TypeMessage {

    protected $id = self::SENDTIP;
    protected $name = "tipæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
    protected $description = "tipæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "tipæ¬„ã«".$message."ã¨é€ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$player->sendTip($this->getSendMessage());
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SendTitle extends TypeMessage {

    protected $id = self::SENDTITLE;
    protected $name = "titleæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
    protected $description = "titleæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "titleæ¬„ã«".$message."ã¨é€ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
        $player->addTitle($this->getSendMessage(), "", 20, 100, 20);
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\lang\TranslationContainer;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SendVoiceMessage extends TypeMessage {

    protected $id = self::SENDVOICEMESSAGE;
    protected $name = "éŸ³å£°ä»˜ãã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ã‚‹";
    protected $description = "éŸ³å£°ä»˜ãã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸Â§7<message>Â§fã‚’é€ã‚‹";

	public function getMessage() {
		$message = $this->getSendMessage();
		return "éŸ³å£°ä»˜ãã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸(".$message.")ã‚’é€ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
        $text = new TranslationContainer($this->getSendMessage());
        $player->sendMessage($text);
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\math\Vector3;
use pocketmine\level\Level;
use pocketmine\block\Block;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetBlocks extends TypePosition {

    protected $id = self::SET_BLOCKS;
    protected $name = "æŒ‡å®šã—ãŸç¯„å›²ã«ãƒ–ãƒ­ãƒƒã‚¯ã‚’è¨­ç½®ã™ã‚‹";
    protected $description = "Â§7<level>Â§fãƒ¯ãƒ¼ãƒ«ãƒ‰ã®Â§7<spos>Â§f~Â§7<epos>Â§fã«Â§7<id>Â§fã®ãƒ–ãƒ­ãƒƒã‚¯ã‚’è¨­ç½®ã™ã‚‹";

	public function getMessage() {
		if($this->getValues() === false) return false;
		$spos = $this->getStartPosition();
		$epos = $this->getEndPosition();
		$level = $this->getLevel();
		$block = $this->getBlock();
		$sx = min($spos->x, $epos->x);
		$sy = min($spos->y, $epos->y);
		$sz = min($spos->z, $epos->z);
		$ex = max($spos->x, $epos->x);
		$ey = max($spos->y, $epos->y);
		$ez = max($spos->z, $epos->z);
		return $level->getFolderName()."ã®".$sx.",".$sy.",".$sz."ï½ž".$ex.",".$ey.",".$ez."ã«".$block->getId().":".$block->getDamage()."ã‚’è¨­ç½®ã™ã‚‹";
	}

	public function getStartPosition() {
		return $this->getValues()[0];
	}

	public function getEndPosition() {
		return $this->getValues()[1];
	}

	public function getLevel() {
		return $this->getValues()[2];
	}

	public function getBlock() {
		return $this->getValues()[3];
	}

	public function setSettings(Vector3 $spos, Vector3 $epos, Level $level, Block $block) {
		$this->setValues([$spos, $epos, $level, $block]);
	}

	public function parse(string $content) {
        $settings = explode(";", $content);
        if(!isset($settings[3])) return false;
        $spos = parent::parse($settings[0]);
        if(!($spos instanceof Vector3)) return false;
        $epos = parent::parse($settings[1]);
        if(!($epos instanceof Vector3)) return false;
        $level = Server::getInstance()->getLevelByName($settings[2]);
        if(!($level instanceof Level)) return false;
        $ids = explode(":", $settings[3]);
        $block = Block::get($ids[0], isset($ids[1]) ? $ids[1] : 0);
        return [$spos, $epos, $level, $block];
	}

	public function execute() {
		if($this->getValues() === false) return false;
		$spos = $this->getStartPosition();
		$epos = $this->getEndPosition();
		$level = $this->getLevel();
		$block = $this->getBlock();
		$sx = min($spos->x, $epos->x);
		$sy = min($spos->y, $epos->y);
		$sz = min($spos->z, $epos->z);
		$ex = max($spos->x, $epos->x);
		$ey = max($spos->y, $epos->y);
		$ez = max($spos->z, $epos->z);
		for($x = $sx; $x <= $ex; $x ++) {
			for($y = $sy; $y <= $ey; $y ++) {
				for($z = $sz; $z <= $ez; $z ++) {
					$level->setBlock(new Vector3($x, $y, $z), $block);
				}
			}
		}
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$settings = $this->parse($default);
		$spos_str = $default;
		$epos_str = "";
		$level_str = "";
		$id = "";
		if($settings !== false) {
			$spos = $settings[0];
			$spos_str = $spos->x.",".$spos->y.",".$spos->z;
			$epos = $settings[1];
			$epos_str = $epos->x.",".$epos->y.",".$epos->z;
			$level = $settings[2];
			$level_str = $level->getFolderName();
			$block = $settings[3];
			$id = $block->getId().":".$block->getDamage();
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<spos>Â§f æœ€åˆã®ä½ç½®ã‚’,ã§åŒºåˆ‡ã£ã¦å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 0,0,0", $spos_str),
                Elements::getInput("\nÂ§7<epos>Â§f æœ€å¾Œã®ä½ç½®ã‚’,ã§åŒºåˆ‡ã£ã¦å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5,10,5", $epos_str),
                Elements::getInput("\nÂ§7<level>Â§f ãƒ¯ãƒ¼ãƒ«ãƒ‰åã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) world", $level_str),
                Elements::getInput("\nÂ§7<id>Â§f è¨­ç½®ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "" or $datas[2] === "" or $datas[3] === "" or $datas[4] === "") {
    		$status = null;
    	} else {
	    	$settings = $this->parse($datas[1].";".$datas[2].";".$datas[3].";".$datas[4]);
	    	if($settings === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1].";".$datas[2].";".$datas[3].";".$datas[4], "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetGamemode extends Process {

    protected $id = self::SET_GAMEMODE;
    protected $name = "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’å¤‰æ›´ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’Â§7<gamemode>Â§fã«ã™ã‚‹";

	public function getGamemode() {
		return $this->getValues();
	}

	public function setGamemode(int $gamemode) {
		$this->setValues($gamemode);
	}

	public function parse(string $content) {
		$gamemode = Server::getInstance()->getGamemodeFromString($content);
		if($gamemode === -1) return false;
		return $gamemode;
	}

	public function getMessage() {
		$gamemode = $this->getGamemode();
		if($gamemode === false) return false;
		return "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’".$gamemode."ã«å¤‰æ›´ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$gamemode = $this->getGamemode();
		if($gamemode === false) {
			$player->sendMessage("Â§c[".$this->getName()."] ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
			return;
		}
		$player->setGamemode($gamemode);
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$gamemode = $this->parse($default);
		if($gamemode === false) {
			if($default !== "") $mes .= "Â§cã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“Â§f";
			$gamemode = 0;
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getDropdown("\nÂ§7<gamemode>Â§f ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’é¸æŠžã—ã¦ä¸‹ã•ã„", ["ã‚µãƒã‚¤ãƒãƒ«", "ã‚¯ãƒªã‚¨ã‚¤ãƒ†ã‚£ãƒ–", "ã‚¢ãƒ‰ãƒ™ãƒ³ãƒãƒ£ãƒ¼", "ã‚¹ãƒšã‚¯ãƒ†ã‚¤ã‚¿ãƒ¼"], $gamemode),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$gamemode = $this->parse($datas[1]);
	    	if($gamemode === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\math\Vector3;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetHealth extends Process {

    protected $id = self::SET_HEALTH;
    protected $name = "ä½“åŠ›ã‚’å¤‰æ›´ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ä½“åŠ›ã‚’Â§7<health>Â§fã«ã™ã‚‹";

	public function getMessage() {
		$health = $this->getHealth();
		if($health === false) return false;
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ä½“åŠ›ã‚’".$health."ã«ã™ã‚‹";
	}

	public function getHealth() {
		return $this->getValues();
	}

	public function setHealth(int $health) {
		$this->setValues($health);
	}

	public function parse(string $content) {
        $health = (int)$content;
        if($health <= 0) return false;
    	return $health;
	}

	public function execute() {
		$player = $this->getPlayer();
		$health = $this->gethealth();
		if($health === false) {
			$player->sendMessage("Â§c[".$this->getName()."] ä½“åŠ›ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„");
			return;
		}
		$player->setHealth($health);
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$health = $this->parse($default);
		if($health === false) {
			if($default !== "") $mes = "Â§cä½“åŠ›ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„Â§f";
			$health = $default;
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<health>Â§f ä½“åŠ›ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 10", $health),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$health = $this->parse($datas[1]);
	    	if($health === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetImmobile extends Process {

    protected $id = self::SET_IMMOBILE;
    protected $name = "å‹•ã‘ãªã„ã‚ˆã†ã«ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ãªã„ã‚ˆã†ã«ã™ã‚‹";

	public function getMessage() {
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ãªã„ã‚ˆã†ã«ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$player->setImmobile();
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetItem extends Process {

    protected $id = self::SET_ITEM;
    protected $name = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã®æŒ‡å®šã—ãŸå ´æ‰€ã«ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã™ã‚‹";
    protected $description = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã®Â§7<index>Â§fã«idãŒÂ§7<id>Â§fã®Â§7<name>Â§fã¨ã„ã†åå‰ã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’Â§7<count>Â§fè¿½åŠ ã™ã‚‹";

	public function getMessage() {
		if($this->getValues()) return false;
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		$index = $this->getIndex();
		return "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã®".$index."ã«(".$item->getId().":".$item->getDamage().",".$item->getName().")"."ã‚’".$item->getCount()."å€‹è¿½åŠ ã™ã‚‹";
	}

	public function getIndex() {
		return $this->getValues()[0];
	}

	public function getItem() {
		return $this->getValues()[1];
	}

	public function setItems(int $index, Item $item) {
		$this->setValues([$index, $item]);
	}

	public function parse(string $id) {
		if(!preg_match("/\s*([0-9]+)\s*,\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*:?\s*(\.*)\s*/", $id, $ids)) return false;
		$item = Item::get((int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3], empty($ids[4]) ? 0 : (int)$ids[4]);
		if(!empty($ids[5])) $item->setCustomName($ids[5]);
		return [(int)$ids[1], $item];
	}

	public function execute() {
		$player = $this->getPlayer();
		if($this->getValues() === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$item = $this->getItem();
		$index = $this->getIndex();
		$player->getInventory()->setItem($index, $item);
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$items = $this->parse($default);
		$id = $default;
		$count = "";
		$name = "";
		$index = "";
		if($items === false and $default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“\n(idã¯æ•°å­—ã§0ä»¥ä¸Šã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„)Â§f";
		} elseif($items[1] instanceof Item) {
			$item = $items[1];
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			$name = $item->hasCustomName() ? $item->getName() : "";
			if($count === 0) $mes .= "Â§eå€‹æ•°ãŒ0ã«ãªã£ã¦ã„ã¾ã™Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("Â§7<id>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getInput("Â§7<count>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $count),
                Elements::getInput("Â§7<name>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã«ä»˜ã‘ãŸã„åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(ç©ºç™½ãªã‚‰ãã®ã¾ã¾ã®åå‰ã§ã™)", "ä¾‹) aieuo", $name),
                Elements::getInput("Â§7<index>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã™ã‚‹å ´æ‰€ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 0", $index),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$id = explode(":", $datas[1]);
    	if(!isset($id[1])) $id[1] = 0;
    	$ids_str = $datas[4].",".$id[0].":".$id[1].":".$datas[2].($datas[3] !== "" ? ":".$datas[3] : "");
    	if($datas[1] === "" or $datas[2] === "" or $datas[4] === "") {
    		$status = null;
    	} else {
	    	$ids = $this->parse($ids_str);
	    	if($ids === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $ids_str, "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\math\Vector3;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetMaxHealth extends SetHealth {

    protected $id = self::SET_MAXHEALTH;
    protected $name = "æœ€å¤§ä½“åŠ›ã‚’å¤‰æ›´ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®æœ€å¤§ä½“åŠ›ã‚’Â§7<health>Â§fã«ã™ã‚‹";

	public function getMessage() {
		$health = $this->getHealth();
		if($health === false) return false;
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®æœ€å¤§ä½“åŠ›ã‚’".$health."ã«ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$health = $this->getHealth();
		if($health === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æœ€å¤§ä½“åŠ›ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„");
			return;
		}
		$player->setMaxHealth($health);
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetNametag extends Process {

    protected $id = self::SET_NAMETAG;
    protected $name = "åå‰ã‚’å¤‰ãˆã‚‹";
    protected $description = "è¡¨ç¤ºã™ã‚‹åå‰ã‚’Â§7<name>Â§fã«å¤‰ãˆã‚‹";

	public function getMessage() {
		return "è¡¨ç¤ºã™ã‚‹åå‰ã‚’".$this->getChangeName()."ã«ã™ã‚‹";
	}

	public function getChangeName() {
		return $this->getValues();
	}

	public function setChangeName(string $name) {
		$this->setValues($name);
	}

	public function execute() {
		$player = $this->getPlayer();
		$name = $this->getChangeName();
    	$player->setNametag($name);
    	$player->setDisplayName($name);
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<name>Â§f å¤‰ãˆã‚‹åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetScale extends Process {

    protected $id = self::SET_SCALE;
    protected $name = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ã‚µã‚¤ã‚ºã‚’å¤‰ãˆã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ã‚µã‚¤ã‚ºã‚’Â§7<scale>Â§fã«ã™ã‚‹";

	public function getMessage() {
		$scale = $this->getScale();
		if($scale === false) return false;
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã®ã‚µã‚¤ã‚ºã‚’".$scale."ã«ã™ã‚‹";
	}

	public function getScale() {
		return $this->getValues();
	}

	public function setScale(float $scale) {
		$this->setValues($scale);
	}

	public function parse(string $content) {
		$scale = (float)$content;
		if($scale <= 0) return false;
        return $scale;
	}

	public function execute() {
		$player = $this->getPlayer();
		$scale = $this->getScale();
		if($slace === false) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$item = $player->getInventory()->getItemInHand();
        $item->addEnchantment($enchant);
		$player->getInventory()->setItemInHand($item);
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$scale = $this->parse($default);
		if($scale === false and $default !== "") {
			$scale = $default;
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“\nå€¤ã¯0ã‚ˆã‚Šå¤§ããã—ã¦ãã ã•ã„Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<scale>Â§f å¤§ãã•ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 2", $scale),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$scale = $this->parse($datas[1]);
	    	if($scale === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\entity\Entity;
use pocketmine\level\Position;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\types\EntityLink;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetSitting extends TypePosition {

    protected $id = self::SET_SITTING;
    protected $name = "åº§ã‚‰ã›ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’Â§7<pos>Â§fã«åº§ã‚‰ã›ã‚‹";

	public function getMessage() {
		$pos = $this->getPosition();
		if($pos === false) return false;
		return $pos->__toString()."ã§åº§ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$pos = $this->getPosition();
		if(!($pos instanceof Position)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
        $pk = new AddEntityPacket();
        $pk->entityRuntimeId = ++Entity::$entityCount;
        $pk->type = 84;
        $pk->position = $pos;
        $pk->links = [new EntityLink($pk->entityRuntimeId, $player->getId(), EntityLink::TYPE_RIDER)];
        $pk->metadata = [
			Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_INVISIBLE]
		];
        $player->dataPacket($pk);
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\level\Position;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class SetSleeping extends TypePosition {

    protected $id = self::SET_SLEEPING;
    protected $name = "å¯ã‹ã›ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’Â§7<pos>Â§fã«å¯ã‹ã›ã‚‹";

	public function getMessage() {
		$pos = $this->getPosition();
		if($pos === false) return false;
		return $pos->__toString()."ã§å¯ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$pos = $this->getPosition();
		if(!($pos instanceof Position)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
		$player->sleepOn($pos);
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TakeMoney extends TypeMoney {

    protected $id = self::TAKEMONEY;
    protected $name = "æ‰€æŒé‡‘ã‚’æ¸›ã‚‰ã™";
    protected $description = "æ‰€æŒé‡‘ã‚’Â§7<amount>Â§fæ¸›ã‚‰ã™";

	public function getMessage() {
		return "æ‰€æŒé‡‘ã‚’".$this->getAmount()."æ¸›ã‚‰ã™";
	}

	public function execute() {
		$player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if($economy === null) {
            $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            return;
        }
        $economy->takeMoney($player->getName(), $this->getAmount());
	}
}<?php

namespace aieuo\ip\processes;

use pocketmine\level\Position;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Teleport extends TypePosition {

    protected $id = self::TELEPORT;
    protected $name = "ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹";
    protected $description = "Â§7<pos>Â§fã«ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹";

	public function getMessage() {
		$pos = $this->getPosition();
		if($pos === false) return false;
		return $pos->__toString()."ã«ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$pos = $this->getPosition();
		if(!($pos instanceof Position)) {
			$player->sendMessage("Â§c[".$this->getName()."] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“");
			return;
		}
        $player->teleport($pos);
	}
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeCommand extends Process {

	public function getCommand() {
		return $this->getValues();
	}

	public function setCommand(string $command) {
		$this->setValues($command);
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<command>Â§f å®Ÿè¡Œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) help", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$command = $this->parse($datas[1]);
	    	if($command === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeItem extends Process {

	public function getItem() {
		return $this->getValues();
	}

	public function setItem(Item $item) {
		$this->setValues($item);
	}

	public function parse(string $id) {
		if(!preg_match("/\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*:?\s*(\.*)\s*/", $id, $ids)) return false;
		$item = Item::get((int)$ids[1], empty($ids[2]) ? 0 : (int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3]);
		if(!empty($ids[4])) $item->setCustomName($ids[4]);
		return $item;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		$name = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			$name = $item->hasCustomName() ? $item->getName() : "";
			if($count === 0) $mes .= "Â§eå€‹æ•°ãŒ0ã«ãªã£ã¦ã„ã¾ã™Â§f";
		} elseif($default !== "") {
			$mes .= "Â§cæ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“\n(idã¯æ•°å­—ã§0ä»¥ä¸Šã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„)Â§f";
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("Â§7<id>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1:0", $id),
                Elements::getInput("Â§7<count>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã®æ•°ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 5", $count),
                Elements::getInput("Â§7<name>Â§f ã‚¢ã‚¤ãƒ†ãƒ ã«ä»˜ã‘ãŸã„åå‰ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„(ç©ºç™½ãªã‚‰ãã®ã¾ã¾ã®åå‰ã§ã™)", "ä¾‹) aieuo", $name),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$id = explode(":", $datas[1]);
    	if(!isset($id[1])) $id[1] = 0;
    	$ids_str = $id[0].":".$id[1].":".$datas[2].":".$datas[3];
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$ids = $this->parse($ids_str);
	    	if($ids === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $ids_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeMessage extends Process {

	public function getSendMessage() {
		return $this->getValues();
	}

	public function setSendMessage(string $message) {
		$this->setValues($message);
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<message>Â§f é€ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) aieuo", $default),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\Processes;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypeMoney extends Process {

	public function getAmount() {
		return $this->getValues();
	}

	public function setAmount(int $amount) {
		$this->setValues($amount);
	}

	public function parse(string $amount) {
		$amount = (int)mb_convert_kana($amount, "n");
		return $amount;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$money = $this->parse($default);
		if($money <= 0) $money = $default;
		if($money <= 0 and $default !== "") $mes .= "Â§e1ä»¥ä¸Šã®æ•°å­—ã‚’å…¥åŠ›ã™ã‚‹ã“ã¨ã‚’æŽ¨å¥¨ã—ã¾ã™Â§f";
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)."\n"),
                Elements::getInput("\nÂ§7<amount>Â§f å€¤æ®µã‚’å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1000", $money),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\level\Position;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class TypePosition extends Process {

	public function getPosition() {
		return $this->getValues();
	}

	public function setPosition(string $pos) {
		$this->setValues($pos);
	}

	public function parse(string $pos) {
	    if(!preg_match("/\s*(-?[0-9]+\.?[0-9]*)\s*,\s*(-?[0-9]+\.?[0-9]*)\s*,\s*(-?[0-9]+\.?[0-9]*)\s*,?\s*(.*)\s*/", $pos, $matches)) return false;
	    if(empty($matches[4])) $matches[4] = "world";
        return new Position((float)$matches[1], (float)$matches[2], (float)$matches[3], Server::getInstance()->getLevelByName($matches[4]));
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$pos = $this->parse($default);
		if($pos instanceof Position) {
			if($pos->level === null) {
				$mes .= "Â§cãƒ¯ãƒ¼ãƒ«ãƒ‰ãŒå­˜åœ¨ã—ãªã„ã‹èª­ã¿è¾¼ã¾ã‚Œã¦ã„ã¾ã›ã‚“Â§f";
				$position = $default;
			} else {
				$position = $pos->x.",".$pos->y.",".$pos->z.",".$pos->level->getFolderName();
			}
		} else {
			if($default !== "") $mes .= "Â§cæ›¸ãæ–¹ãŒæ­£ã—ãã‚ã‚Šã¾ã›ã‚“Â§f";
			$position = $default;
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput("\nÂ§7<pos>Â§f åº§æ¨™ã¨ãƒ¯ãƒ¼ãƒ«ãƒ‰åã‚’,ã§åŒºåˆ‡ã£ã¦å…¥åŠ›ã—ã¦ãã ã•ã„", "ä¾‹) 1,15,30,world", $position),
                Elements::getToggle("å‰Šé™¤ã™ã‚‹"),
                Elements::getToggle("ã‚­ãƒ£ãƒ³ã‚»ãƒ«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	if($datas[1] === "") {
    		$status = null;
    	} else {
	    	$pos = $this->parse($datas[1]);
	    	if($pos === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class UnSetImmobile extends Process {

	protected $id = self::UNSET_IMMOBILE;
    protected $name = "å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹";
    protected $description = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹";

	public function getMessage() {
		return "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹";
	}

	public function execute() {
		$player = $this->getPlayer();
		$player->setImmobile(false);
	}
}<?php

namespace aieuo\ip;

class Session {

	const BLOCK = 0;
	const COMMAND = 1;
	const EVENT = 2;
	const CHAIN = 3;

    private $valid = false;
	private $if_type = self::BLOCK;
    private $datas = [];

	public function isValid(){
		return $this->valid;
	}

	public function setValid($valid = true, $del = true){
        $this->valid = $valid;
		if(!$valid and $del)$this->removeAllData();
	}

	public function getIfType(){
		return $this->if_type;
	}

	public function setIfType($type){
		$this->if_type = $type;
    }

	public function getData($id){
		if(!isset($this->datas[$id]))return "";
		return $this->datas[$id];
    }

	public function setData($id, $data){
		$this->datas[$id] = $data;
    }

	public function removeData($id){
		unset($this->datas[$id]);
    }

    public function removeAllData() {
        $this->datas = [];
    }
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class DelayedCommandTask extends Task {
	public function __construct($player, $command) {
        $this->player = $player;
        $this->command = $command;
	}

	public function onRun(int $currentTick) {
		$this->player->getServer()->dispatchCommand($this->player, $this->command);
	}
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class KickTask extends Task {
	public function __construct($player, $reason) {
        $this->player = $player;
        $this->reason = $reason;
	}

	public function onRun(int $currentTick) {
		$this->player->kick($this->reason);
	}
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class SaveTask extends Task {
    public function __construct($owner) {
        $this->owner = $owner;
    }

    public function onRun(int $currentTick) {
        $this->owner->getBlockManager()->save();
        $this->owner->getCommandManager()->save();
        $this->owner->getEventManager()->save();
        $this->owner->getChainManager()->save();
        $this->owner->getVariableHelper()->save();
    }
}<?php

namespace aieuo\ip\utils;

use aieuo\ip\ifPlugin;
use aieuo\ip\conditions\Condition;
use aieuo\ip\processes\Process;

class Messages {

    public static function createMessage($ifs, $matchs, $elses){
    	$mes = "ã‚‚ã—\n";
        foreach($ifs as $if){
            $content = Condition::get($if["id"]);
            $content->setValues($content->parse($if["content"]));
            $mes .= $content->getMessage() === false ?
                        $content->getDescription()."Â§f,\n":
                        $content->getMessage()."Â§f,\n";
        }
        $mes .= "\nãªã‚‰\n";
        foreach ($matchs as $match) {
            $process1 = Process::get($match["id"]);
            $process1->setValues($process1->parse($match["content"]));
            $mes .= $process1->getMessage() === false ?
                        $process1->getDescription()."Â§f,\n":
                        $process1->getMessage()."Â§f,\n";
        }
        $mes .= "\næ¡ä»¶ã«åˆã‚ãªã‹ã£ãŸã‚‰\n";
        foreach ($elses as $else) {
            $process2 = Process::get($else["id"]);
            $process2->setValues($process2->parse($else["content"]));
            $mes .= $process2->getMessage() === false ?
                        $process2->getDescription()."Â§f,\n":
                        $process2->getMessage()."Â§f,\n";
        }
        return $mes;
    }
}<?php

namespace aieuo\ip\variable;

class ListVariable extends Variable {

	public $type = Variable::LIST;

	public function __construct($name, $value) {
		$this->name = $name;
		$this->value = $value;
	}

	public function Addition(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::LIST) {
			return new StringVariable("ERROR", "ãƒªã‚¹ãƒˆã«ãƒªã‚¹ãƒˆä»¥å¤–ã‚’è¶³ã™ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = array_merge($this->getValue(), $var->getValue());
		return new ListVariable($name, $result);
	}

	public function Subtraction(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::LIST) {
			return new StringVariable("ERROR", "ãƒªã‚¹ãƒˆã‹ã‚‰ãƒªã‚¹ãƒˆä»¥å¤–ã‚’å¼•ãã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = array_diff($this->getValue(), $var->getValue());
		$result = array_values($result);
		return new ListVariable($name, $result);
	}

	public function Multiplication(Variable $var, string $name = "result") {
		return new StringVariable("ERROR", "ãƒªã‚¹ãƒˆã¯æŽ›ã‘ç®—ã§ãã¾ã›ã‚“");
		// TODO    convert StringVariable
	}

	public function Division(Variable $var, string $name = "result") {
		return new StringVariable("ERROR", "ãƒªã‚¹ãƒˆã¯å‰²ã‚Šç®—ã§ãã¾ã›ã‚“");
	}

	public function Modulo(Variable $var, string $name = "result") {
		return new StringVariable("ERROR", "ãƒªã‚¹ãƒˆã¯å‰²ã‚Šç®—ã§ãã¾ã›ã‚“");
	}

	public function getValueFromIndex($index) {
		if(!isset($this->value[$index])) return null;
		return $this->value[$index];
	}

	public function getCount() {
		return count($this->value);
	}

	public function toStringVariable($glue = ", ") {
		$variable = new StringVariable($this->getName(), implode($glue, $this->getValue()));
		return $variable;
	}
}<?php

namespace aieuo\ip\variable;

class NumberVariable extends Variable {

	public $type = Variable::NUMBER;

	public function __construct($name, $value) {
		$this->name = $name;
		$this->value = $value;
	}

	public function Addition(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ•°å­—ã«æ–‡å­—åˆ—ã‚’è¶³ã™ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = $this->getValue() + $var->getValue();
		return new NumberVariable($name, $result);
	}

	public function Subtraction(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ•°å­—ã‹ã‚‰æ–‡å­—åˆ—ã‚’å¼•ãã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = $this->getValue() - $var->getValue();
		return new NumberVariable($name, $result);
	}

	public function Multiplication(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ•°å­—ã«æ–‡å­—åˆ—ã‚’æŽ›ã‘ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = $this->getValue() * $var->getValue();
		return new NumberVariable($name, $result);
	}

	public function Division(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ•°å­—ã‚’æ–‡å­—åˆ—ã§å‰²ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		if($var->getValue() === 0) {
			return new StringVariable("ERROR", "0ã§å‰²ã‚Œã¾ã›ã‚“");
		}
		$result = $this->getValue() / $var->getValue();
		return new NumberVariable($name, $result);
	}

	public function Modulo(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ•°å­—ã‚’æ–‡å­—åˆ—ã§å‰²ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		if($var->getValue() === 0) {
			return new StringVariable("ERROR", "0ã§å‰²ã‚Œã¾ã›ã‚“");
		}
		$result = $this->getValue() % $var->getValue();
		return new NumberVariable($name, $result);
	}

	public function toStringVariable() {
		$variable = new StringVariable($this->getName(), (string)$this->getValue());
		return $variable;
	}
}<?php

namespace aieuo\ip\variable;

class StringVariable extends Variable{

	public $type = Variable::STRING;

	public function __construct($name, $value) {
		$this->name = $name;
		$this->value = $value;
	}

	public function Addition(Variable $var, string $name = "result") {
		$result = $this->getValue().$var->getValue();
		return new StringVariable($name, $result);
	}

	public function Subtraction(Variable $var, string $name = "result") {
		$result = str_replace((string)$var->getValue(), "", $this->getValue());
		return new StringVariable($name, $result);
	}

	public function Multiplication(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::NUMBER) {
			return new StringVariable("ERROR", "æ–‡å­—åˆ—ã¨æ–‡å­—åˆ—ã‚’æŽ›ã‘ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		if($var->getValue() <= 0) {
			return new StringVariable("ERROR", "æŽ›ã‘ã‚‹æ•°ã¯1ä»¥ä¸Šã«ã—ã¦ãã ã•ã„");
		}
		$result = str_repeat($this->getValue(), (int)$var->getValue());
		return new StringVariable($name, $result);
	}

	public function Division(Variable $var, string $name = "result") {
		if($var->getType() !== Variable::STRING) {
			return new StringVariable("ERROR", "æ–‡å­—åˆ—ã‚’æ–‡å­—åˆ—ä»¥å¤–ã§å‰²ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“");
		}
		$result = explode($var->getValue(), $this->getValue());
		return new ListVariable($name, $result);
	}

	public function Modulo(Variable $var, string $name = "result") {
		return new StringVariable("ERROR", "æ–‡å­—åˆ—ã¯å‰²ã‚Šç®—ã§ãã¾ã›ã‚“");
	}
}<?php

namespace aieuo\ip\variable;

class Variable {

	const STRING = 0;
	const NUMBER = 1;
	const LIST = 2;

	public static function create($name, $value, $type = self::STRING) {
		if($type === self::STRING) {
			$var = new StringVariable($name, $value);
		} elseif($type === self::NUMBER) {
			$var = new NumberVariable($name, $value);
		} elseif($type === self::LIST) {
			if(is_array($value)) {
				$var = new ListVariable($name, $value);
			} else {
				$var = (new StringVariable("string", $value))->Division(new StringVariable("delimiter", ", "), $name);
			}
		}
		return $var;
	}

	public function getName(){
		return $this->name;
	}

	public function getValue(){
		return $this->value;
	}

	public function getType(){
		return $this->type;
	}
}<?php

namespace aieuo\ip\variable;

class VariableHelper {

    const STRING_VARIABLE = 0;
    const INTEGER_VARIABLE = 1;
    const ARRAY_VARIABLE = 2;

    private $variables = [];

    public function __construct($owner){
        $this->owner = $owner;
    }

    public function loadDataBase() {
        $owner = $this->owner;
        if(!file_exists($owner->getDataFolder()."if.db")) {
            $this->db = new \SQLite3($owner->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
        }else{
            $this->db = new \SQLite3($owner->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE);
        }
        $this->db->query("CREATE TABLE IF NOT EXISTS variables (name TEXT, value TEXT, type INT)");
    }

    /**
     * @param  string $name
     * @param  bool $save
     * @return bool
     */
    public function exists(String $name, $save = false){
        if(isset($this->variables[$name]) and !$save)return true;
        $datas = $this->db->query("SELECT * FROM variables WHERE name=\"$name\"")->fetchArray();
        return !empty($datas);
    }

    /**
     * @param  string $name
     * @param  bool $save
     * @return string | Variable
     */
    public function get(String $name, $save = false){
        if(isset($this->variables[$name]) and !$save) return $this->variables[$name];
        if(!$this->exists($name, true)) return "";
        $datas = $this->db->query("SELECT * FROM variables WHERE name=\"$name\"")->fetchArray();
        return Variable::create($datas["name"], $datas["value"], $datas["type"]);
    }

    /**
     * @param Variable $val
     * @param bool $save
     */
    public function add(Variable $val, $save = false){
        if(!$save){
            $this->variables[$val->getName()] = $val;
            return;
        }
        if(!($val instanceof StringVariable)) $val = $val->toStringVariable();
        $name = $val->getName();
        $value = $val->getValue();
        $type = $val->getType();
        if($this->exists($name, true)){
            $this->db->query("UPDATE variables set value=\"$value\" WHERE name=\"$name\"");
        }else{
            $this->db->query("INSERT OR REPLACE INTO variables VALUES(\"$name\",\"$value\",$type)");
        }
    }

    /**
     * @param  String $name
     * @return bool
     */
    public function del(String $name){
        if(isset($this->variables[$name])){
            unset($this->variables[$name]);
        }
        if(!$this->exists($name))return false;
        $this->db->query("DELETE FROM variables WHERE name=\"$name\"");
        return true;
    }

    public function save(){
        unset($this->variables["result"]);
        foreach ($this->variables as $variable) {
            $this->add($variable, true);
        }
        $this->variables = [];
    }

    /**
     * æ–‡å­—åˆ—ã®ä¸­ã«ã‚ã‚‹å¤‰æ•°ã‚’ç½®ãæ›ãˆã‚‹
     * @param  string $string
     * @param  array $variables
     * @return string
     */
    public function replaceVariables($string, $variables = []){
        foreach (["/\[({[^{}]+})\]/" => 2, "/({[^{}]+})/" => 1] as $pattern => $n) {
            while(preg_match_all($pattern, $string, $matches)){
                foreach ($matches[0] as $name) {
                    $name = mb_substr($name, $n, -$n);
                    $val = isset($variables[$name]) ? $variables[$name] : $this->get($name);
                    if(!($val instanceof Variable)) {
                        $string = str_replace("{".$name."}", "Â§cUndefined variable: ".$name."Â§r", $string);
                        continue;
                    }
                    $string = $this->replace($string, $val);
                }
            }
        }
        return $string;
    }

    /**
     * å¤‰æ•°ã‚’ç½®ãæ›ãˆã‚‹
     * @param  string $string
     * @param  Variable $variable
     * @return string
     */
    public function replace($string, $variable) {
        if(strpos($string, "{".$variable->getName()."}") === false) return $string;
        if($variable instanceof ListVariable) {
            $haystack = explode("{".$variable->getName()."}", $string)[1];
            if(preg_match("/^\[([0-9]+)\].*/", $haystack, $index)) {
                $value = $variable->getValueFromIndex($index[1]);
                if($value === null) $value = "Â§cUndefined index: ".$variable->getName()."[".$index[1]."]Â§r";
                $string = str_replace("{".$variable->getName()."}"."[".$index[1]."]", $value, $string);
                return $string;
            }
            if(preg_match("/^\.([a-z]+[0-9a-z]*).*/", $haystack, $method)) {
                if($method[1] === "length") {
                    $string = str_replace("{".$variable->getName()."}".".".$method[1], $variable->getCount(), $string);
                }
                return $string;
            }
            $variable = $variable->toStringVariable();
        }
        $string = str_replace("{".$variable->getName()."}", $variable->getValue(), $string);
        return $string;
    }

    /**
     * æ–‡å­—åˆ—ãŒå¤‰æ•°ã‹èª¿ã¹ã‚‹
     * @param  string  $variable
     * @return boolean
     */
    public function isVariable(string $variable) {
        return preg_match("/^{.+}$/", $variable);
    }

    /**
     * æ–‡å­—åˆ—ã«å¤‰æ•°ãŒå«ã¾ã‚Œã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹
     * @param  string  $variable
     * @return boolean
     */
    public function containsVariable(string $variable) {
        return preg_match("/.*{.+}.*/", $variable);
    }

    /**
     * æ–‡å­—åˆ—ã®åž‹ã‚’èª¿ã¹ã‚‹
     * @param  string $string
     * @return int
     */
    public function getType(string $string) {
        if(substr($string, 0, 5) === "(str)") {
            $type = Variable::STRING;
        } elseif(substr($string, 0, 5) === "(num)") {
            $type = Variable::NUMBER;
        } elseif(substr($string, 0, 6) === "(list)") {
            $type = Variable::LIST;
        } elseif(is_numeric($string)) {
            $type = Variable::NUMBER;
        } else {
            $type = Variable::STRING;
        }
        return $type;
    }

    /**
     * æ–‡å­—åˆ—ã®åž‹ã‚’å¤‰æ›´ã™ã‚‹
     * @param  string $string
     * @return string | float | value
     */
    public function changeType(string $value) {
        if(mb_substr($value, 0, 5) === "(str)") {
            $value = mb_substr($value, 5);
        } elseif(mb_substr($value, 0, 5) === "(num)") {
            $value = mb_substr($value, 5);
            if(!$this->containsVariable($value)) $value = (float)$value;
        } elseif(substr($value, 0, 6) === "(list)") {
            $value = mb_substr($value, 6);
            if(!$this->containsVariable($value)) $value = Variable::create("list", $value, Variable::LIST)->getValue();
        } elseif(is_numeric($value)) {
            $value = (float)$value;
        }
        return $value;
    }
}n“Ôêßß;Ø|}ö¿úëB   GBMB