<?php echo "Altay plugin if v2.4.0\nThis file has been generated using Turanic at Tue, 13 Nov 2018 12:34:10 +0900.\n----------------\n";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(); ?>
S               a:9:{s:4:"name";s:2:"if";s:7:"version";s:5:"2.4.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";a:0:{}s:11:"description";s:0:"";s:7:"authors";a:1:{i:0;s:5:"aieuo";}s:7:"website";s:0:"";s:12:"creationDate";i:1542080050;}
   plugin.ymlk   3Fê[k   5LÁ¶      #   src/aieuo/ip/commands/ifCommand.phpM  3Fê[M  ¯Áy¶      )   src/aieuo/ip/economy/EconomyAPILoader.phpf  3Fê[f  þ<™ì¶      &   src/aieuo/ip/economy/EconomyLoader.phpÿ   3Fê[ÿ   ¬„æž¶      *   src/aieuo/ip/economy/MoneySystemLoader.phpW  3Fê[W  ÎY¶      *   src/aieuo/ip/economy/PocketMoneyLoader.php×  3Fê[×  2ä2+¶         src/aieuo/ip/EventListener.phpq  3Fê[q  Ä%å¶         src/aieuo/ip/form/Elements.phpà  3Fê[à  à²„¥¶         src/aieuo/ip/form/Form.phpò/  3Fê[ò/  –À-¶         src/aieuo/ip/form/Parts.phpJ  3Fê[J  Å“™¶         src/aieuo/ip/ifAPI.php–i  3Fê[–i  ›Ò;¶         src/aieuo/ip/ifPlugin.phpA  3Fê[A  ½iÆô¶      %   src/aieuo/ip/manager/BlockManager.phpû  3Fê[û  ö³ðf¶      '   src/aieuo/ip/manager/CommandManager.php¡  3Fê[¡  –Ùó¶      %   src/aieuo/ip/manager/EventManager.phpw  3Fê[w  Ü)3Û¶      "   src/aieuo/ip/manager/ifManager.phpŸ
  3Fê[Ÿ
  1ÔØë¶         src/aieuo/ip/Session.php¯  3Fê[¯  òº½¶      (   src/aieuo/ip/task/DelayedCommandTask.phpm  3Fê[m  Žuà¶         src/aieuo/ip/task/SaveTask.php¯  3Fê[¯  K8 ×¶         src/aieuo/ip/utils/Messages.phpUa  3Fê[Ua  ¯1œß¶      "   src/aieuo/ip/variable/Variable.php  3Fê[  1Å
¶      (   src/aieuo/ip/variable/VariableHelper.phpd	  3Fê[d	  ÐKvì¶      ---
name: if
main: aieuo\ip\ifPlugin
version: 2.4.0
api:
- 3.0.0
- 4.0.0
load: POSTWORLD
author: aieuo
...
<?php

namespace aieuo\ip\commands;

use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;

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;
	}

	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 = Form::getSelectIfTypeForm();
			Form::sendForm($sender, $form, Form::getFormId("SelectIfTypeForm"));
			return true;
		}
		switch ($args[0]) {
			case 'block':
				if(isset($args[1])){
					$session = $sender->ifSession;
					$session->setValid();
					$session->setIfType(Session::BLOCK);
					switch ($args[1]) {
						case "add":
							$session->setData("type", "add");
							$sender->sendMessage("è¿½åŠ ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
							return true;
						case "add_empty":
							$session->setData("type", "add_empty");
							$sender->sendMessage("è¿½åŠ ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
							return true;
						case "edit":
							$session->setData("type", "edit");
							$sender->sendMessage("ç·¨é›†ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
							return true;
						case "check":
							$session->setData("type", "check");
							$sender->sendMessage("ç¢ºèªã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
							return true;
						case "del":
							$session->setData("type", "del");
							$sender->sendMessage("å‰Šé™¤ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
							return true;
						case "cancel":
							$session->setValid(false);
							$sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
							return true;
					}
					return true;
				}
				$form = Form::getSelectBlockActionForm();
				Form::sendForm($sender, $form, Form::getFormId("SelectBlockActionForm"));
				break;
			case 'command':
				if(isset($args[1])){
					$session = $sender->ifSession;
					$session->setValid();
					$session->setIfType(Session::COMMAND);
					$manager = $this->owner->getCommandManager();
					switch ($args[1]) {
						case "add":
							$session->setData("type", "add_");
							$form = Form::getAddCommandForm();
							Form::sendForm($sender, $form, Form::getFormId("AddCommandForm"));
							return true;
						case "add_empty":
							$session->setData("type", "add_empty");
							$form = Form::getAddCommandForm();
							Form::sendForm($sender, $form, Form::getFormId("AddCommandForm"));
							return true;
						case "edit":
							$session->setData("type", "edit");
							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"]);
								$form = Form::getEditIfForm($mes);
								Form::sendForm($sender, $form, Form::getFormId("EditIfForm"));
								return true;
							}
							$form = Form::getSelectCommandForm();
							Form::sendForm($sender, $form, Form::getFormId("SelectCommandForm"));
							return true;
						case "check":
							$session->setData("type", "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);
								return true;
							}
							$form = Form::getSelectCommandForm();
							Form::sendForm($sender, $form, Form::getFormId("SelectCommandForm"));
							return true;
						case "del":
							$session->setData("type", "del");
							if(isset($args[2])){
								if(!$manager->isAdded($args[2])){
									$sender->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
									$session->setValid(false);
									return true;
								}
								$manager->remove($args[2]);
								$sender->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
								return true;
							}
							$form = Form::getSelectCommandForm();
							Form::sendForm($sender, $form, Form::getFormId("SelectCommandForm"));
							return true;
						case "cancel":
							$session->setValid(false);
							$sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
							return true;
					}
				}
				$form = Form::getSelectCommandActionForm();
				Form::sendForm($sender, $form, Form::getFormId("SelectCommandActionForm"));
				break;
			case 'event':
				if(isset($args[1])){
	                $session = $sender->ifSession;
	                $session->setValid();
	                $session->setIfType(Session::EVENT);
	                switch ($args[1]) {
	                    case "add":
	                    case "add_empty":
	                    case "edit":
	                    case "check":
	                    case "del":
	                        $session->setData("type", $args[1]);
	                        break;
	                    case "cancel":
	                        $session->setValid(false);
	                        $sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
	                        break;
	                }
	                $form = Form::getSelectEventForm();
	                Form::sendForm($sender, $form, Form::getFormId("SelectEventForm"));
	                return true;
				}
                $form = Form::getSelectEventActionForm();
                Form::sendForm($sender, $form, Form::getFormId("SelectEventActionForm"));
				break;
			default:
				$form = Form::getSelectIfTypeForm();
				Form::sendForm($sender, $form, Form::getFormId("SelectIfTypeForm"));
				break;
		}
		return true;
	}
}<?php

namespace aieuo\ip\economy;

class EconomyAPILoader extends EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney($name){
		return (int)$this->plugin->mymoney($name);
	}

	public function addMoney($name, $money){
		$money = (int)$money;
        $this->plugin->addMoney($name, $money);
		return true;
	}

	public function takeMoney($name, $money){
		$money = (int)$money;
        $this->plugin->reduceMoney($name, $money);
		return true;
	}
}<?php

namespace aieuo\ip\economy;

class EconomyLoader {

	public function getMoney($name){
		return false;
	}

	public function addMoney($name, $money){
		return false;
	}

	public function takeMoney($name, $money){
		return false;
	}
}<?php

namespace aieuo\ip\economy;

class MoneySystemLoader extends EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney($name){
		return (int)$this->plugin->check($name);
	}

	public function addMoney($name, $money){
		$money = (int)$money;
		$this->plugin->addMoney($name, $money);
		return true;
	}

	public function takeMoney($name, $money){
		$money = (int)$money;
		$this->plugin->takeMoney($name, $money);
		return true;
	}
}<?php

namespace aieuo\ip\economy;

class PocketMoneyLoader extends EconomyLoader{

	private $plugin;

	public function __construct($plugin){
		$this->plugin = $plugin;
	}

	public function getPlugin(){
		return $this->plugin;
	}

	public function getMoney($name){
		return (int)$this->plugin->getMoney($name);
	}

	public function addMoney($name, $money){
		$money = (int)$money;
		$mymoney = $this->plugin->getMoney($name);
        $this->plugin->setMoney($name, $mymoney + $money);
		return true;
	}

	public function takeMoney($name, $money){
		$money = (int)$money;
		$mymoney = $this->plugin->getMoney($name);
        $this->plugin->setMoney($name, $mymoney - $money);
		return true;
	}
}<?php

namespace aieuo\ip;

use pocketmine\event\Listener;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
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\CraftItemEvent;

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");

        $manager = $this->getOwner()->getCommandManager();
        if($manager->isAdded(mb_substr($event->getMessage(), 1))){
            $datas = $manager->get(mb_substr($event->getMessage(), 1));
            $manager->executeIfMatchCondition($event->getPlayer(), $datas["if"], $datas["match"], $datas["else"]);
        }
    }
    public function join(PlayerJoinEvent $event){
        $this->onEvent($event, "PlayerJoinEvent");

        $player = $event->getPlayer();
        if($player->isOp()){
            $session = new Session();
            $player->ifSession = $session;
        }
    }
    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 entityDeath(EntityDeathEvent $event){
        $this->onEvent($event, "EntityDeathEvent");
    }
    public function onEvent($event, $eventname){
        switch ($eventname) {
            case 'PlayerInteractEvent':
            case 'PlayerChatEvent':
            case 'PlayerCommandPreprocessEvent':
            case 'PlayerJoinEvent':
            case 'PlayerQuitEvent':
            case 'PlayerToggleFlightEvent':
            case 'BlockBreakEvent':
            case 'BlockPlaceEvent':
                $player = $event->getPlayer();
                break;
            case 'EntityDamageEvent':
            case 'EntityDeathEvent':
                $player = $event->getEntity();
                if(!$player instanceof Player)return;
                break;
        }
        $manager = $this->getOwner()->getEventManager();
        $datas = $manager->getByEvent($eventname);
        $manager->setOptions($eventname, $event);
        foreach ($datas as $key => $data) {
            $data = $manager->get($key);
            $manager->executeIfMatchCondition($player, $data["if"], $data["match"], $data["else"]);
        }
    }

	public function interact(PlayerInteractEvent $event){
		$this->onEvent($event, "PlayerInteractEvent");

		$player = $event->getPlayer();
        $manager = $this->getOwner()->getBlockManager();
        $block = $event->getBlock();
        $pos = $manager->getPosition($block);
		if($player->isOp()){
			if(($session = $player->ifSession)->isValid()){
				$type = $session->getData("type");
				$manager = $this->getOwner()->getBlockManager();
				switch ($type) {
					case 'add':
                        if($manager->isAdded($pos)){
                            $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯ã™ã§ã«è¿½åŠ ã•ã‚Œã¦ã„ã¾ã™");
                            return;
                        }
                        $form = Form::getAddIfForm();
                        Form::sendForm($player, $form, Form::getFormId("AddIfForm"));
                        $session->setData("if_key", $pos);
						return;
					case 'add_empty':
                        if($manager->isAdded($pos)){
                            $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯ã™ã§ã«è¿½åŠ ã•ã‚Œã¦ã„ã¾ã™");
                            return;
                        }
						$manager->set($manager->getPosition($block));
	                    $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
						break;
					case 'edit':
	                    if(!$manager->isAdded($pos)){
	                        $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
	                        return;
	                    }
	                    $datas = $manager->get($pos);
	                    $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
	                    $form = Form::getEditIfForm($mes);
	                    Form::sendForm($player, $form, Form::getFormId("EditIfForm"));
	                    $session->setData("if_key", $pos);
						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 'del':
	                    $pos = $manager->getPosition($block);
	                    if(!$manager->isAdded($pos)){
	                        $player->sendMessage("ãã®ãƒ–ãƒ­ãƒƒã‚¯ã«ã¯è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
	                        return;
	                    }
	                    $manager->remove($pos);
	                    $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
						break;
				}
				$session->setValid(false);
                return;
			}
		}
        if($manager->isAdded($pos)){
            $datas = $manager->get($pos);
            $manager->executeIfMatchCondition($player, $datas["if"], $datas["match"], $datas["else"]);
        }
	}


    public function Receive(DataPacketReceiveEvent $event){
        $pk = $event->getPacket();
        $player = $event->getPlayer();
        $name = $player->getName();
        if(!$player->isOp())return;
        if($pk instanceof ModalFormResponsePacket){
            if($pk->formId === Form::getFormId("SelectIfTypeForm")){
                $data = json_decode($pk->formData);
                if($data === null) {
                   return;
                }
                $session = $player->ifSession;
                switch ($data) {
                	case 0:
		        		$form = Form::getSelectBlockActionForm();
		        		Form::sendForm($player, $form, Form::getFormId("SelectBlockActionForm"));
                		break;
                	case 1:
                        $form = Form::getSelectCommandActionForm();
                        Form::sendForm($player, $form, Form::getFormId("SelectCommandActionForm"));
                		break;
                	case 2:
                        $form = Form::getSelectEventActionForm();
                        Form::sendForm($player, $form, Form::getFormId("SelectEventActionForm"));
                		break;
                }
            }

            if($pk->formId === Form::getFormId("SelectBlockActionForm")){
                $data = json_decode($pk->formData);
                if($data === null) {
                   return;
                }
                $session = $player->ifSession;
                $session->setValid();
                $session->setIfType(Session::BLOCK);
                switch ($data) {
                	case 0:
                        $session->setData("type", "add");
                        $player->sendMessage("è¿½åŠ ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                		break;
                	case 1:
						$session->setData("type", "add_empty");
                		$player->sendMessage("è¿½åŠ ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                		break;
                	case 2:
						$session->setData("type", "edit");
                		$player->sendMessage("ç·¨é›†ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                		break;
                	case 3:
						$session->setData("type", "check");
                		$player->sendMessage("ç¢ºèªã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                		break;
                	case 4:
						$session->setData("type", "del");
                		$player->sendMessage("å‰Šé™¤ã™ã‚‹ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ã¦ãã ã•ã„");
                		break;
                	case 5:
                		$session->setValid(false);
                		$player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                		break;
                }
            }

            if($pk->formId === Form::getFormId("EditIfForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                	$session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                if($type === Session::BLOCK){
                	$manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                }
                $key = $session->getData("if_key");
                $datas = $manager->get($key);
                if($data == 0){
                    $form = Form::getEditContentsForm($datas["if"]);
                    $session->setData("type", "if");
                }elseif($data == 1){
                    $form = Form::getEditContentsForm($datas["match"]);
                    $session->setData("type", "match");
                }elseif($data == 2){
                    $form = Form::getEditContentsForm($datas["else"]);
                    $session->setData("type", "else");
                }else{
                    $manager->remove($key);
                    $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
                    $session->setValid(false);
                    return;
                }
	            Form::sendForm($player, $form, Form::getFormId("EditIfContentsForm"));
            }

            if($pk->formId === Form::getFormId("EditIfContentsForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                $event = false;
                if($type === Session::BLOCK){
                	$manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                    $event = true;
                }
                $key = $session->getData("if_key");
                $datas = $manager->get($key);
                if($data == 0){
                    $form = Form::getAddContentsForm($session->getData("type"), $event);
                    Form::sendForm($player, $form, Form::getFormId("AddContentsForm"));
                }else{
                	$if = $datas[$session->getData("type")][--$data];
                    $form = Form::getDetailForm((int)$if["id"], $if["content"]);
                    Form::sendForm($player, $form, Form::getFormId("DetailForm"));
                    $session->setData("num", $data);
                    $session->setData("id", $if["id"]);
                    $session->setData("content", $if["content"]);
                }
            }

            if($pk->formId === Form::getFormId("AddContentsForm")){
            	$json = str_replace([",]",",,"], [",\"\"]",",\"\","], $pk->formData);
                $data = json_decode($json);
                $session = $player->ifSession;
                if($data === null) {
                	$session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                if($type === Session::BLOCK){
                	$manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                }
                if($session->getData("type") == "if"){
                	$id = $manager->getIfIdByListNumber($data[0]);
                }else{
                	$id = $manager->getExeIdByListNumber($data[0]);
                }
                $manager->add($session->getData("if_key"), $session->getData("type"), $id, $data[1]);
                $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
            }

            if($pk->formId === Form::getFormId("DetailForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                	$session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                if($type === Session::BLOCK){
                    $manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                }
                if($data == 0){
                    $form = Form::getUpdateContentsForm($session->getData("type"), $session->getData("id"), $session->getData("content"));
                    Form::sendForm($player, $form, Form::getFormId("UpdateContentsForm"));
                }elseif($data == 1){
                    $manager->del($session->getData("if_key"), $session->getData("type"), $session->getData("num"));
                    $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
                }
            }

            if($pk->formId === Form::getFormId("UpdateContentsForm")){
                $json = str_replace([",]",",,"], [",\"\"]",",\"\","], $pk->formData);
                $data = json_decode($json);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                if($type === Session::BLOCK){
                    $manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                }
                $manager->del($session->getData("if_key"), $session->getData("type"), $session->getData("num"));
                $manager->add($session->getData("if_key"), $session->getData("type"), $session->getData("id"), $data[1]);
                $player->sendMessage("å¤‰æ›´ã—ã¾ã—ãŸ");
            }

            if($pk->formId === Form::getFormId("AddIfForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $id_1 = ifAPI::getIfIdByListNumber($data[0]);
                $id_2 = ifAPI::getExeIdByListNumber($data[1]);
                $id_3 = ifAPI::getExeIdByListNumber($data[2]);
                $form = Form::createIfContentForm($id_1, $id_2, $id_3);
                Form::sendForm($player, $form, Form::getFormId("InputContentsForm"));
                $session->setData("id_1", $id_1);
                $session->setData("id_2", $id_2);
                $session->setData("id_3", $id_3);
            }

            if($pk->formId === Form::getFormId("InputContentsForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $type = $session->getIfType();
                if($type === Session::BLOCK){
                    $manager = $this->getOwner()->getBlockManager();
                }elseif($type === Session::COMMAND){
                    $manager = $this->getOwner()->getCommandManager();
                    $manager->setOptions($session->getData("if_key"), $session->getData("description"), $session->getData("permission"));
                }elseif($type === Session::EVENT){
                    $manager = $this->getOwner()->getEventManager();
                    $manager->setOptions($session->getData("event"));
                    $key = $manager->add_empty();
                    $session->setData("if_key", $key);
                }
                $key = $session->getData("if_key");
                $manager->add($key, "if", $session->getData("id_1"), (string)$data[0]);
                $manager->add($key, "match", $session->getData("id_2"), (string)$data[1]);
                $manager->add($key, "else", $session->getData("id_3"), (string)$data[2]);
                $session->setValid(false);
                $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
            }

            if($pk->formId === Form::getFormId("SelectCommandActionForm")){
                $data = json_decode($pk->formData);
                if($data === null) {
                   return;
                }
                $session = $player->ifSession;
                $session->setValid();
                $session->setIfType(Session::COMMAND);
                switch ($data) {
                    case 0:
                        $session->setData("type", "add");
                        break;
                    case 1:
                        $session->setData("type", "add_empty");
                        break;
                    case 2:
                        $session->setData("type", "edit");
                        break;
                    case 3:
                        $session->setData("type", "check");
                        break;
                    case 4:
                        $session->setData("type", "del");
                        break;
                    case 5:
                        $session->setValid(false);
                        $player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                        break;
                }
                switch ($data) {
                    case 0:
                    case 1:
                        $form = Form::getAddCommandForm();
                        Form::sendForm($player, $form, Form::getFormId("AddCommandForm"));
                        break;
                    case 2:
                    case 3:
                    case 4:
                        $form = Form::getSelectCommandForm();
                        Form::sendForm($player, $form, Form::getFormId("SelectCommandForm"));
                        break;
                }
            }

            if($pk->formId === Form::getFormId("AddCommandForm")){
                $json = str_replace([",]",",,"], [",\"\"]",",\"\","], $pk->formData);
                $data = json_decode($json);
                $session = $player->ifSession;
                $manager = $this->getOwner()->getCommandManager();
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                if($data[0] === ""){
                    $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
                    return;
                }
                if($manager->exists($data[0])){
                    $player->sendMessage("Â§cãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™");
                    return;
                }
                if($manager->isAdded($data[0])){
                    $player->sendMessage("Â§eãã®ã‚³ãƒžãƒ³ãƒ‰ã¯æ—¢ã«è¿½åŠ ã—ã¦ã„ã¾ã™");
                    return;
                }
                if($data[1] === "")$data[1] = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™";
                if($session->getData("type") == "add_empty"){
                    $manager->setOptions($data[0], $data[1], $data[2] == 0 ? "op" : "default");
                    $manager->set($data[0]);
                    $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
                    $session->setValid(false);
                    return;
                }
                $session->setData("if_key", $data[0]);
                $session->setData("description", $data[1]);
                $session->setData("permission", $data[2] == 0 ? "op" : "default");
                $form = Form::getAddIfForm();
                Form::sendForm($player, $form, Form::getFormId("AddIfForm"));
            }

            if($pk->formId === Form::getFormId("SelectCommandForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                if($data[0] === ""){
                    $player->sendMessage("å¿…è¦äº‹é …ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„");
                    return;
                }
                $session->setData("if_key", $data[0]);
                $type = $session->getData("type");
                $manager = $this->getOwner()->getCommandManager();
                if(!$manager->isAdded($data[0])){
                    $player->sendMessage("ãã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã¾ã è¿½åŠ ã•ã‚Œã¦ã„ã¾ã›ã‚“");
                    return;
                }
                if($type == "edit"){
                    $datas = $manager->get($data[0]);
                    $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                    $form = Form::getEditIfForm($mes);
                    Form::sendForm($player, $form, Form::getFormId("EditIfForm"));
                }elseif($type == "check"){
                    $datas = $manager->get($data[0]);
                    $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                    $player->sendMessage($mes);
                }elseif($type == "del"){
                    $manager->remove($data[0]);
                    $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
                }
            }

            if($pk->formId === Form::getFormId("SelectEventActionForm")){
                $data = json_decode($pk->formData);
                if($data === null) {
                   return;
                }
                $session = $player->ifSession;
                $session->setValid();
                $session->setIfType(Session::EVENT);
                switch ($data) {
                    case 0:
                        $session->setData("type", "add");
                        break;
                    case 1:
                        $session->setData("type", "add_empty");
                        break;
                    case 2:
                        $session->setData("type", "edit");
                        break;
                    case 3:
                        $session->setData("type", "check");
                        break;
                    case 4:
                        $session->setData("type", "del");
                        break;
                    case 5:
                        $session->setValid(false);
                        $player->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                        break;
                }
                $form = Form::getSelectEventForm();
                Form::sendForm($player, $form, Form::getFormId("SelectEventForm"));
            }

            if($pk->formId === Form::getFormId("SelectEventForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $eventname = ifAPI::getEventName($data[0]);
                $session->setData("event", $eventname);
                $type = $session->getData("type");
                $manager = $this->getOwner()->getEventManager();
                $manager->setOptions($eventname);
                switch ($type) {
                    case 'add':
                        $form = Form::getAddIfForm(true);
                        Form::sendForm($player, $form, Form::getFormId("AddIfForm"));
                        $session->setData("if_key", null);
                        break;
                    case 'add_empty':
                        $manager->add_empty();
                        $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
                        $session->setValid(false);
                        break;
                    case 'edit':
                    case 'check':
                    case 'del':
                        $all = $manager->getByEvent($eventname);
                        $datas = [];
                        foreach ($all as $key => $value) {
                            $datas[] = $manager->get($key);
                        }
                        $form = Form::getEditEventForm($eventname, $datas);
                        Form::sendForm($player, $form, Form::getFormId("EditEventForm"));
                        break;
                }
            }

            if($pk->formId === Form::getFormId("EditEventForm")){
                $data = json_decode($pk->formData);
                $session = $player->ifSession;
                if($data === null) {
                    $session->setValid(false, false);
                    return;
                }
                $type = $session->getData("type");
                $manager = $this->getOwner()->getEventManager();
                $manager->setOptions($session->getData("event"));
                $datas = $manager->get($data);
                if($data == $manager->getCount($session->getData("event"))){
                    $form = Form::getAddIfForm(true);
                    Form::sendForm($player, $form, Form::getFormId("AddIfForm"));
                    $session->setData("if_key", null);
                    return;
                }
                switch ($type) {
                    case 'edit':
                        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                        $form = Form::getEditIfForm($mes);
                        Form::sendForm($player, $form, Form::getFormId("EditIfForm"));
                        $session->setData("if_key", $data);
                        break;
                    case 'check':
                        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                        $player->sendMessage($mes);
                        $session->setValid(false);
                        break;
                    case 'del':
                        $manager->remove($data);
                        $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
                        $session->setValid(false);
                        break;
                }
            }
        }
    }
}<?php

namespace aieuo\ip\form;

class Elements {
    public static function getLabel($text){
        return [
            "type" => "label",
            "text" => $text
        ];
    }

    public static function getInput($text, $placeholder = "", $default = ""){
        return [
            "type" => "input",
            "text" => $text,
            "default" => $default,
            "placeholder" => $placeholder
        ];
    }

    public static function getToggle($text){
        return [
            "type" => "toggle",
            "text" => $text
        ];
    }

    public static function getDropdown($text, $options, $default = 0){
    	$default = $options[$default];
    	return [
            "type" => "dropdown",
            "text" => $text,
            "options" => $options,
            "defaultOptionIndex" => $default
        ];
    }

    public function getButton($text){
    	return [
    		"text" => $text
    	];
    }
}<?php

namespace aieuo\ip\form;

use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;

use aieuo\ip\ifPlugin;
use aieuo\ip\ifAPI;
use aieuo\ip\utils\Messages;

class Form {

    private static $formId;

    public static function sendForm($player, $data, $id){
        $pk = new ModalFormRequestPacket();
        $pk->formId = $id;
        $pk->formData = $data;
        $player->dataPacket($pk);
    }

    public static function registerFormId($name){
        self::$formId[$name] = mt_rand(1, 999999999);
    }

    public static function registerFormIds(){
        self::registerFormId("SelectIfTypeForm");
        self::registerFormId("SelectIfForm");
        self::registerFormId("SelectBlockActionForm");
        self::registerFormId("EditIfForm");
        self::registerFormId("EditIfContentsForm");
        self::registerFormId("AddContentsForm");
        self::registerFormId("UpdateContentsForm");
        self::registerFormId("DetailForm");
        self::registerFormId("AddIfForm");
        self::registerFormId("InputContentsForm");
        self::registerFormId("SelectCommandActionForm");
        self::registerFormId("AddCommandForm");
        self::registerFormId("SelectCommandForm");
        self::registerFormId("SelectEventActionForm");
        self::registerFormId("SelectEventForm");
        self::registerFormId("EditEventForm");
    }

    public static function getFormId($type){
        return self::$formId[$type];
    }

////////////////////////////////block////////////////////////////////
    public static function getSelectBlockActionForm(){
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                [
                    "text" => "è¿½åŠ ã™ã‚‹"
                ],
                [
                    "text" => "ç©ºã®ç‰©ã‚’è¿½åŠ ã™ã‚‹",
                ],
                [
                    "text" => "ç·¨é›†ã™ã‚‹"
                ],
                [
                    "text" => "ç¢ºèªã™ã‚‹"
                ],
                [
                    "text" => "å‰Šé™¤ã™ã‚‹"
                ],
                [
                    "text" => "ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹"
                ]
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
////////////////////////////////command////////////////////////////////
    public static function getSelectCommandActionForm(){
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                [
                    "text" => "è¿½åŠ ã™ã‚‹"
                ],
                [
                    "text" => "ã‚³ãƒžãƒ³ãƒ‰ã ã‘è¿½åŠ ã™ã‚‹",
                ],
                [
                    "text" => "ç·¨é›†ã™ã‚‹"
                ],
                [
                    "text" => "ç¢ºèªã™ã‚‹"
                ],
                [
                    "text" => "å‰Šé™¤ã™ã‚‹"
                ],
                [
                    "text" => "ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹"
                ]
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
    public static function getAddCommandForm(){
        $data = [
            "type" => "custom_form",
            "title" => "è¿½åŠ ",
            "content" => [
                Elements::getInput("è¿½åŠ ã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ã®åå‰", "æœ€åˆã®/ã‚’å¤–ã—ã¦"),
                Elements::getInput("ã‚³ãƒžãƒ³ãƒ‰ã®èª¬æ˜Ž"),
                Elements::getDropdown("æ¨©é™", ["opã ã‘", "å…¨å“¡ä½¿ãˆã‚‹"], 1)
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
    public static function getSelectCommandForm(){
        $data = [
            "type" => "custom_form",
            "title" => "ã‚³ãƒžãƒ³ãƒ‰é¸æŠž",
            "content" => [
                Elements::getInput("ã‚³ãƒžãƒ³ãƒ‰ã®åå‰", "æœ€åˆã®/ã‚’å¤–ã—ã¦"),
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
////////////////////////////////event////////////////////////////////
    public static function getSelectEventActionForm(){
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                [
                    "text" => "è¿½åŠ ã™ã‚‹"
                ],
                [
                    "text" => "ç©ºã®ç‰©ã‚’è¿½åŠ ã™ã‚‹",
                ],
                [
                    "text" => "ç·¨é›†ã™ã‚‹"
                ],
                [
                    "text" => "ç¢ºèªã™ã‚‹"
                ],
                [
                    "text" => "å‰Šé™¤ã™ã‚‹"
                ],
                [
                    "text" => "ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹"
                ]
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
    public static function getSelectEventForm(){
        $data = [
            "type" => "custom_form",
            "title" => "ã‚¤ãƒ™ãƒ³ãƒˆé¸æŠž",
            "content" => [
                Parts::getEventListDropdown()
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public static function getEditEventForm($event, $datas){
        $data = [
            "type" => "form",
            "title" => $event,
            "content" => "ã‚¤ãƒ™ãƒ³ãƒˆã®ç·¨é›†",
            "buttons" => []
        ];
        foreach ($datas as $key => $value) {
            $mes = Messages::createMessage($value["if"], $value["match"], $value["else"]);
            $data["buttons"][] = ["text" => mb_substr(str_replace("\n", " ", $mes), 0, 30)."ãƒ»ãƒ»ãƒ»"];
        }
        $data["buttons"][] = ["text" => "è¿½åŠ ã™ã‚‹"];
        $json = self::encodeJson($data);
        return $json;
    }
////////////////////////////////all////////////////////////////////
    public static function getSelectIfTypeForm(){
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => [
                [
                    "text" => "ãƒ–ãƒ­ãƒƒã‚¯"
                ],
                [
                    "text" => "ã‚³ãƒžãƒ³ãƒ‰",
                ],
                [
                    "text" => "ã‚¤ãƒ™ãƒ³ãƒˆ"
                ]
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public static function getEditIfForm($mes){
        $data = [
            "type" => "form",
            "title" => "ç·¨é›†",
            "content" => $mes,
            "buttons" => [
                [
                    "text" => "ã‚‚ã—~ã‚’ç·¨é›†ã™ã‚‹"
                ],
                [
                    "text" => "æ¡ä»¶ã«åˆã£ãŸæ™‚ã‚’ç·¨é›†ã™ã‚‹",
                ],
                [
                    "text" => "æ¡ä»¶ã«åˆã‚ãªã‹ã£ãŸæ™‚ã‚’ç·¨é›†ã™ã‚‹"
                ],
                [
                    "text" => "å‰Šé™¤ã™ã‚‹"
                ]
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }
    public static function getEditContentsForm($datas){
        $data = [
            "type" => "form",
            "title" => "ç·¨é›†",
            "content" => "",
            "buttons" => []
        ];
        $data["buttons"][] = ["text" => "è¿½åŠ ã™ã‚‹"];
        foreach ($datas as $key => $value) {
            $data["buttons"][] = ["text" => Messages::getMessage($value["id"], $value["content"])];
        }
        $data = self::encodeJson($data);
        return $data;
    }

    public static function getDetailForm($id, $content){
        $data = [
            "type" => "form",
            "title" => "è©³ç´°",
            "content" => Messages::getMessage($id, $content),
            "buttons" => [
                ["text" => "ç·¨é›†ã™ã‚‹"],
                ["text" => "å‰Šé™¤ã™ã‚‹"]
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public static function getSelectIfForm($ifs){
        $buttons = [];
        foreach ($ifs as $if){
            $buttons[] = ["text" => $if];
        }
        $data = [
            "type" => "form",
            "title" => "é¸æŠž",
            "content" => "Â§7ãƒœã‚¿ãƒ³ã‚’æŠ¼ã—ã¦ãã ã•ã„",
            "buttons" => $buttons
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public static function getAddContentsForm($type, $event = false){
        if($type == "if"){
            $list = Parts::getIflistDropdown();
        }else{
            $list = Parts::getExelistDropdown(0, $event);
        }
        $data = [
            "type" => "custom_form",
            "title" => "è¿½åŠ ",
            "content" => [
                $list,
                Elements::getInput("å€¤ã‚’å…¥åŠ›ã—ã¦ä¸‹ã•ã„")
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public static function getUpdateContentsForm($type, $id, $defaltInput = ""){
        if($type == "if"){
            $mes = Parts::getIflist()[ifAPI::getListNumberByIfId($id)];
        }else{
            $mes = Parts::getExelist()[ifAPI::getListNumberByExeId($id)];
        }
        $data = [
            "type" => "custom_form",
            "title" => "è¿½åŠ ",
            "content" => [
                Elements::getLabel($mes),
                Elements::getInput("å€¤ã‚’å…¥åŠ›ã—ã¦ä¸‹ã•ã„", "", $defaltInput)
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public static function getAddIfForm($event = false){
        $data = [
            "type" => "custom_form",
            "title" => "è¿½åŠ ",
            "content" => [
                Parts::getIflistDropdown(),
                Parts::getExelistDropdown(0, $event),
                Parts::getExelistDropdown(0, $event)
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }
//////////////////////////////////////////////////////////
    public static function createIfContentForm($type1, $type2, $type3, $encode = true, $event = false){
        $messages1 = Messages::getFormMessage($type1, $event);//ã‚‚ã—
        $messages2 = Messages::getFormMessage($type2);//åˆã£ãŸã‚‰
        $messages3 = Messages::getFormMessage($type3);//åˆã‚ãªã‹ã£ãŸã‚‰

        if($messages1["type"] == "input"){
            $input1 = Elements::getInput($messages1["message"], $messages1["placeholder"]);
        }else{
            $input1 = Elements::getLabel($messages1["message"]);
        }
        if($messages2["type"] == "input"){
            $input2 = Elements::getInput($messages1["next"].$messages2["message"], $messages2["placeholder"]);
        }else{
            $input2 = Elements::getLabel($messages2["message"]);
        }
        if($messages3["type"] == "input"){
            $input3 = Elements::getInput($messages2["next"]."åˆã‚ãªã‹ã£ãŸã‚‰\n".$messages3["message"], $messages3["placeholder"]);
        }else{
            $input3 = Elements::getLabel("åˆã‚ãªã‹ã£ãŸã‚‰\n".$messages3["message"]);
        }

        $content[] = $input1;
        $content[] = $input2;
        $content[] = $input3;

        $content[] = Elements::getLabel($messages3["next"]);

        $data = [
            "type" => "custom_form",
            "title" => "ifPlugin",
            "content" => $content
        ];
        if($encode)$data = self::encodeJson($data);
        return $data;
    }

//////////////////////////////////////////////////////////////
    public static function encodeJson($data){
        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE);
        return $json;
    }
}<?php

namespace aieuo\ip\form;

class Parts {

	public static function getIfList(){
    	$list = [
            "ä½•ã‚‚ç¢ºèªã—ãªã„",
            "ãŠé‡‘ã‚’æ¸›ã‚‰ã™",
            "æŒ‡å®šã—ãŸé‡‘é¡ã‚ˆã‚Šæ‰€æŒé‡‘ãŒå¤šã„ã‹",
            "æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ã‚’æ‰‹ã«æŒã£ã¦ã‚‹ã‹",
            "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ãŒå…¥ã£ã¦ã‚‹ã‹",
            "æŒ‡å®šã—ãŸã‚¢ã‚¤ãƒ†ãƒ ãŒã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚ã‚‹ãªã‚‰å‰Šé™¤ã™ã‚‹",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒopã‹",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹ã‹",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒé£›ã‚“ã§ã„ã‚‹ã‹",
            "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒæŒ‡å®šã—ãŸã‚‚ã®ã ã£ãŸã‚‰",
            "æŒ‡å®šã—ãŸç¯„å›²å†…ã«ã„ãŸã‚‰",
            "ä¹±æ•°ãŒæŒ‡å®šã—ãŸã‚‚ã®ã ã£ãŸã‚‰",
            "äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹",
        ];
        return $list;
	}
    public static function getIflistDropdown($default = 0){
    	$options = self::getIfList();
        $dropdown = Elements::getDropdown("ã‚‚ã—ï½žãªã‚‰", $options, $default);
    	return $dropdown;
    }

    public static function getExeList(){
    	$list = [
            "ä½•ã‚‚ã—ãªã„",
            "ãƒãƒ£ãƒƒãƒˆæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡",
            "tipæ¬„ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡",
            "ã‚¿ã‚¤ãƒˆãƒ«é€ä¿¡",
            "å…¨ä½“ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡",
            "opã ã‘ã«ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡",
            "éŸ³å£°ä»˜ãã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’é€ä¿¡",
            "ã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã™ã‚‹",
            "ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã‚³ãƒžãƒ³ãƒ‰å®Ÿè¡Œ",
            "é…ã‚Œã¦ã‚³ãƒžãƒ³ãƒ‰å®Ÿè¡Œ",
            "ãƒ†ãƒ¬ãƒãƒ¼ãƒˆ",
            "å‹•ã‹ã™",
            "è¨ˆç®—ã™ã‚‹",
            "å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹",
            "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã™ã‚‹",
            "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ ã‚’å‰Šé™¤ã™ã‚‹",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ãªãã™ã‚‹",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹",
            "æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’è¿½åŠ ã™ã‚‹",
            "ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’ä¸Žãˆã‚‹",
            "è¡¨ç¤ºã™ã‚‹åå‰ã‚’å¤‰æ›´ã™ã‚‹",
            "å¯ã‹ã›ã‚‹",
            "åº§ã‚‰ã›ã‚‹",
            "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’å¤‰æ›´ã™ã‚‹",
            "ä½“åŠ›ã‚’å¤‰æ›´ã™ã‚‹",
            "æœ€å¤§ä½“åŠ›ã‚’å¤‰æ›´ã™ã‚‹",
            "æ”»æ’ƒã™ã‚‹",
            "ã‚­ãƒƒã‚¯ã™ã‚‹",
        ];
        return $list;
    }
    public static function getExelistDropdown($default = 0, $event = false){
    	$options = self::getExeList();
        if($event)$options[] = "ã‚¤ãƒ™ãƒ³ãƒˆã‚’ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";
        $dropdown = Elements::getDropdown("æ¡ä»¶ã«å½“ã¦ã¯ã¾ã£ãŸã‚‰ï½žã‚’ã™ã‚‹", $options, $default);
    	return $dropdown;
    }

    public static function getEventListDropdown(){
    	$options = [
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒãƒ£ãƒƒãƒˆã—ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚³ãƒžãƒ³ãƒ‰ã‚’å®Ÿè¡Œã—ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚µãƒ¼ãƒãƒ¼ã«å‚åŠ ã—ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚µãƒ¼ãƒãƒ¼ã‹ã‚‰é€€å®¤ã—ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’å£Šã—ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ–ãƒ­ãƒƒã‚¯ã‚’ç½®ã„ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’å—ã‘ãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒãƒ•ãƒ©ã‚¤çŠ¶æ…‹ã‚’åˆ‡ã‚Šæ›¿ãˆãŸã¨ã",
            "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒæ­»äº¡ã—ãŸã¨ã",
        ];
        $dropdown = Elements::getDropdown("ã‚¤ãƒ™ãƒ³ãƒˆã‚’é¸ã‚“ã§ãã ã•ã„", $options);
    	return $dropdown;
    }
}<?php

namespace aieuo\ip;

use aieuo\ip\manager\ifManager;

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;

class ifAPI {

	const MATCHED = 0;
	const NOT_MATCHED = 1;
	const NOT_FOUND = 2;

    public static function getIfIdByListNumber($num){
        switch ($num){
            case 0:
                return ifPlugin::IF_NO_CHECK;
            case 1:
                return ifPlugin::IF_TAKEMONEY;
            case 2:
                return ifPlugin::IF_OVERMONEY;
            case 3:
                return ifPlugin::IF_HAVEINGITEM;
            case 4:
                return ifPlugin::IF_EXISTITEM;
            case 5:
                return ifPlugin::IF_REMOVEITEM;
            case 6:
                return ifPlugin::IF_IS_OP;
            case 7:
                return ifPlugin::IF_IS_SNEAKING;
            case 8:
                return ifPlugin::IF_IS_FLYING;
            case 9:
                return ifPlugin::IF_GAMEMODE;
            case 10:
                return ifPlugin::IF_IN_AREA;
            case 11:
                return ifPlugin::IF_RANDOM_NUMBER;
            case 12:
                return ifPlugin::IF_COMPARISON;
            default:
                return false;
        }
    }

    public static function getListNumberByIfId($id){
        switch ($id){
            case ifPlugin::IF_NO_CHECK:
            	return 0;
            case ifPlugin::IF_TAKEMONEY:
            	return 1;
            case ifPlugin::IF_OVERMONEY:
            	return 2;
            case ifPlugin::IF_HAVEINGITEM:
            	return 3;
            case ifPlugin::IF_EXISTITEM:
            	return 4;
            case ifPlugin::IF_REMOVEITEM:
            	return 5;
            case ifPlugin::IF_IS_OP:
            	return 6;
            case ifPlugin::IF_IS_SNEAKING:
            	return 7;
            case ifPlugin::IF_IS_FLYING:
            	return 8;
            case ifPlugin::IF_GAMEMODE:
            	return 9;
            case ifPlugin::IF_IN_AREA:
                return 10;
            case ifPlugin::IF_RANDOM_NUMBER:
                return 11;
            case ifPlugin::IF_COMPARISON:
                return 12;
            default:
                return false;
        }
    }

    public static function getExeIdByListNumber($num){
        switch ($num){
            case 0:
                return ifPlugin::DO_NOTHING;
            case 1:
                return ifPlugin::SENDMESSAGE;
            case 2:
                return ifPlugin::SENDTIP;
            case 3:
                return ifPlugin::SENDTITLE;
            case 4:
                return ifPlugin::BROADCASTMESSAGE;
            case 5:
                return ifPlugin::SENDMESSAGE_TO_OP;
            case 6:
                return ifPlugin::SENDVOICEMESSAGE;
            case 7:
                return ifPlugin::COMMAND;
            case 8:
                return ifPlugin::COMMAND_CONSOLE;
            case 9:
                return ifPlugin::DELAYED_COMMAND;
            case 10:
                return ifPlugin::TELEPORT;
            case 11:
                return ifPlugin::MOTION;
            case 12:
                return ifPlugin::CALCULATION;
            case 13:
                return ifPlugin::ADD_VARIABLE;
            case 14:
                return ifPlugin::ADD_ITEM;
            case 15:
                return ifPlugin::REMOVE_ITEM;
            case 16:
                return ifPlugin::SET_IMMOBILE;
            case 17:
                return ifPlugin::UNSET_IMMOBILE;
            case 18:
                return ifPlugin::ADD_ENCHANTMENT;
            case 19:
                return ifPlugin::ADD_EFFECT;
            case 20:
                return ifPlugin::SET_NAMETAG;
            case 21:
                return ifPlugin::SET_SLEEPING;
            case 22:
                return ifPlugin::SET_SITTING;
            case 23:
                return ifPlugin::SET_GAMEMODE;
            case 24:
                return ifPlugin::SET_HEALTH;
            case 25:
                return ifPlugin::SET_MAXHEALTH;
            case 26:
                return ifPlugin::ATTACK;
            case 27:
                return ifPlugin::KICK;
            case 28:
                return ifPlugin::EVENT_CANCELL;
            default:
                return false;
        }
    }

    public static function getListNumberByExeId($num){
        switch ($num){
            case ifPlugin::DO_NOTHING:
            	return 0;
            case ifPlugin::SENDMESSAGE:
            	return 1;
            case ifPlugin::SENDTIP:
            	return 2;
            case ifPlugin::SENDTITLE:
            	return 3;
            case ifPlugin::BROADCASTMESSAGE:
            	return 4;
            case ifPlugin::SENDMESSAGE_TO_OP:
            	return 5;
            case ifPlugin::SENDVOICEMESSAGE:
            	return 6;
            case ifPlugin::COMMAND:
            	return 7;
            case ifPlugin::COMMAND_CONSOLE:
                return 8;
            case ifPlugin::DELAYED_COMMAND:
                return 9;
            case ifPlugin::TELEPORT:
            	return 10;
            case ifPlugin::MOTION:
            	return 11;
            case ifPlugin::CALCULATION:
                return 12;
            case ifPlugin::ADD_VARIABLE:
                return 13;
            case ifPlugin::ADD_ITEM:
                return 14;
            case ifPlugin::REMOVE_ITEM:
            	return 15;
            case ifPlugin::SET_IMMOBILE:
            	return 16;
            case ifPlugin::UNSET_IMMOBILE:
            	return 17;
            case ifPlugin::ADD_ENCHANTMENT:
            	return 18;
            case ifPlugin::ADD_EFFECT:
            	return 19;
            case ifPlugin::SET_NAMETAG:
            	return 20;
            case ifPlugin::SET_SLEEPING:
            	return 21;
            case ifPlugin::SET_SITTING:
            	return 22;
            case ifPlugin::SET_GAMEMODE:
            	return 23;
            case ifPlugin::SET_HEALTH:
            	return 24;
            case ifPlugin::SET_MAXHEALTH:
            	return 25;
            case ifPlugin::ATTACK:
            	return 26;
            case ifPlugin::KICK:
            	return 27;
            case ifPlugin::EVENT_CANCELL:
            	return 28;
            default:
                return false;
        }
    }

    public static function getEventName($num){
        switch ($num) {
            case 0:
                $eventname = "PlayerChatEvent";
                break;
            case 1:
                $eventname = "PlayerCommandPreprocessEvent";
                break;
            case 2:
                $eventname = "PlayerInteractEvent";
                break;
            case 3:
                $eventname = "PlayerJoinEvent";
                break;
            case 4:
                $eventname = "PlayerQuitEvent";
                break;
            case 5:
                $eventname = "BlockBreakEvent";
                break;
            case 6:
                $eventname = "BlockPlaceEvent";
                break;
            case 7:
                $eventname = "EntityDamageEvent";
                break;
            case 8:
                $eventname = "PlayerToggleFlightEvent";
                break;
            case 9:
                $eventname = "PlayerDeathEvent";
                break;
            default:
                $eventname = "";
        }
        return $eventname;
    }

    public function checkMatchCondition($player, $type, $content, $eventname = null, $data = null){
        $result = self::NOT_MATCHED;
        $name = $player->getName();
        switch ($type) {
            case ifPlugin::IF_NO_CHECK:
                $result = self::MATCHED;
                break;
            case ifPlugin::IF_TAKEMONEY:
            	$mymoney = ifManager::getOwner()->getEcomony()->getMoney($name);
                $money = (int)$content;
                if($mymoney === false){
                    $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
                    break;
                }
                if($mymoney >= $money){
                    ifManager::getOwner()->getEconomy()->reduceMoney($name, $money);
                    $result = self::MATCHED;
                }
                break;
            case ifPlugin::IF_OVERMONEY:
            	$mymoney = ifManager::getOwner()->getEcomony()->getMoney($name);
                $money = (int)$content;
                if($mymoney === false){
                    $player->sendMessage("Â§cçµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
                    break;
                }
                if($mymoney >= $money){
                    $result = self::MATCHED;
                }
                break;
            case ifPlugin::IF_HAVEINGITEM:
                $item = $player->getInventory()->getItemInHand();
                $id = explode(":", $content);
                if(!isset($id[1]))$id[1] = 0;
                if(isset($id[2])){
                    if($item->getId() == $id[0] and $item->getDamage() == $id[1] and $item->getCount() >= $id[2]){
                        $result = self::MATCHED;
                    }
                }else{
                    if($item->getId() == $id[0] and $item->getDamage() == $id[1] ){
                        $result = self::MATCHED;
                    }
                }
                break;
            case ifPlugin::IF_EXISTITEM:
                $id = explode(":", $content);
                if(!isset($id[1]))$id[1] = 0;
                if(!isset($id[2]))$id[2] = 1;
                $item = Item::get((int)$id[0], (int)$id[1], (int)$id[2]);
                if($player->getInventory()->contains($item))$result = self::MATCHED;
                break;
            case ifPlugin::IF_REMOVEITEM:
                $ids = explode(":", $content);
                if(!isset($ids[1]))$ids[1] == 0;
                if(isset($ids[2])){
                    $item = Item::get((int)$ids[0], (int)$ids[1], (int)$ids[2]);
                    if($player->getInventory()->contains($item)){
                        $player->getInventory()->removeItem($item);
                        $result = self::MATCHED;
                    }
                }else{
                    $count = 0;
                    foreach ($player->getInventory()->getContents() as $item) {
                        if($item->getId() == $ids[0] and $item->getDamage() == $ids[1]){
                            $count += $item->getCount();
                        }
                    }
                    if($count >= 1){
                        $player->getInventory()->removeItem(Item::get($ids[0], $ids[1], $count));
                        $result = self::MATCHED;
                    }
                }
                break;
            case ifPlugin::IF_IS_OP:
                if($player->isOp())$result = self::MATCHED;
                break;
            case ifPlugin::IF_IS_SNEAKING:
                if($player->isSneaking())$result = self::MATCHED;
                break;
            case ifPlugin::IF_IS_FLYING:
                if($player->isFlying())$result = self::MATCHED;
                break;
            case ifPlugin::IF_GAMEMODE:
                $gamemode = $player->getServer()->getGamemodeFromString($content);
                if($player->getGamemode() == $gamemode)$result = self::MATCHED;
                break;
            case ifPlugin::IF_IN_AREA:
                preg_match("/([xyz]\(-?[0-9\.]+,-?[0-9\.]+\))+/", $content, $matches);
                array_shift($matches);
                $checks = [];
                foreach ($matches as $match) {
                    if(!preg_match("/([xyz])\((-?[0-9\.]+),-?([0-9\.]+)\)/", $match, $matches1))continue;
                    $min = min((float)$matches1[2], (float)$matches1[3]);
                    $max = max((float)$matches1[2], (float)$matches1[3]);
                    $checks[$matches1[1]] = [$min, $max];
                }
                if(count($checks) == 0)break;
                $result = self::MATCHED;
                foreach ($checks as $axis => $value) {
                    if($player->$axis < $value[0] and $player->$axis > $value[1]){
                        $result = self::NOT_MATCHED;
                    }
                }
                break;
            case ifPlugin::IF_RANDOM_NUMBER:
                if(!preg_match("/(-?[0-9]+),(-?[0-9]+);(-?[0-9]+)/", $content, $matches)) break;
                $min = min((int)$matches[1], (int)$matches[2]);
                $max = max((int)$matches[1], (int)$matches[2]);
                $rand = mt_rand($min, $max);
                if($rand == (int)$matches[3])$result = self::MATCHED;
                break;
            case ifPlugin::IF_COMPARISON:
                if(!preg_match("/([^!>=<]+)([!>=<]{1,2})([^!>=<]+)/", $content, $matches)){
                    $player->sendMessage("Â§c[äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f");
                    break;
                }
                $operator = $matches[2];
                $val1 = trim(rtrim($matches[1]));
                $val2 = trim(rtrim($matches[3]));
                switch ($operator){
                    case "=":
                    case "==":
                        if($val1 == $val2)$result = self::MATCHED;
                        break;
                    case "!=":
                    case "=!":
                        if($val1 != $val2)$result = self::MATCHED;
                        break;
                    case ">":
                        if($val1 > $val2)$result = self::MATCHED;
                        break;
                    case "<":
                        if($val1 < $val2)$result = self::MATCHED;
                        break;
                    case ">=":
                    case "=>":
                        if($val1 >= $val2)$result = self::MATCHED;
                        break;
                    case "<=":
                    case "=<":
                        if($val1 <= $val2)$result = self::MATCHED;
                        break;
                    case "><":
                        if(strpos($val1, $val2) !== false)$result = self::MATCHED;
                        break;
                    case "<>":
                        if(strpos($val1, $val2) === false)$result = self::MATCHED;
                        break;
                    default:
                        $player->sendMessage("Â§c[äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹] ãã®çµ„ã¿åˆã‚ã›ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ æ¬¡ã®ä¸­ã‹ã‚‰é¸ã‚“ã§ãã ã•ã„[==|>|>=|<|<=|!=]Â§r");
                        break;
                }
                break;
            default:
                $result = self::NOT_FOUND;
                break;
        }
        return $result;
    }

    public function execute($player, $type, $content){
        $name = $player->getName();
        switch ($type) {
            case ifPlugin::DO_NOTHING:
                break;
            case ifPlugin::SENDMESSAGE:
                $player->sendMessage($content);
                break;
            case ifPlugin::SENDTIP:
                $player->sendTip($content);
                break;
            case ifPlugin::SENDTITLE:
                $player->addTitle($content, "", 20, 100, 20);
                break;
            case ifPlugin::BROADCASTMESSAGE:
                $this->getServer()->broadcastMessage($content);
                break;
            case ifPlugin::SENDMESSAGE_TO_OP:
            	$players = $player->getServer()->getOnlinePlayers();
            	foreach ($players as $op) {
            		if($op->isOp()){
            			$op->sendMessage($content);
            		}
            	}
            case ifPlugin::SENDVOICEMESSAGE:
		        $text = new TranslationContainer($content);
		        $player->sendMessage($text);
		        break;
            case ifPlugin::COMMAND:
                $this->getServer()->dispatchCommand($player, $content);
                break;
            case ifPlugin::COMMAND_CONSOLE:
                $this->getServer()->dispatchCommand(new ConsoleCommandSender, $content);
                break;
            case ifPlugin::DELAYED_COMMAND:
                if(!preg_match("/([0-9]+),(.+)/", $content, $matches)){
                    $player->sendMessage("Â§c[é…ã‚Œã¦ã‚³ãƒžãƒ³ãƒ‰å®Ÿè¡Œ] æ›¸ãæ–¹ãŒæ­£ã—ãã‚ã‚Šã¾ã›ã‚“");
                    break;
                }
                ifManager::getOwner()->getScheduler()->scheduleDelayedTask(new DelayedCommandTask($player, $matches[2]), (int)$matches[1]*20);
                break;
            case ifPlugin::TELEPORT:
                $pos = explode(",", $content);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                if(!isset($pos[3]))$pos[3] = $player->level->getFolderName();
                $player->teleport(new Position((int)$pos[0], (int)$pos[1], (int)$pos[2], $this->getServer()->getLevelByName($pos[3])));
                break;
            case ifPlugin::MOTION:
                $pos = explode(",", $content);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                $player->setMotion(new Vector3((int)$pos[0], (int)$pos[1], (int)$pos[2]));
                break;
            case ifPlugin::CALCULATION:
                if(!preg_match("/([^+ï¼‹-ãƒ¼*\/%ï¼…Ã—Ã·]+)([+ï¼‹-ãƒ¼*\/%Ã—Ã·])([^+ï¼‹-ãƒ¼*\/%Ã—Ã·]+)/", $content, $matches)){
                    $message = "Â§c[è¨ˆç®—ã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                    break;
                }
                $operator = $matches[2];
                $val1 = trim(rtrim($matches[1]));
                $val2 = trim(rtrim($matches[3]));
                switch ($operator){
                    case "+":
                    case "ï¼‹":
                        $val = (new Variable("input", $val1))->Addition($val2);
                        break;
                    case "-":
                    case "ãƒ¼":
                        $val = (new Variable("input", $val1))->Subtraction($val2);
                        break;
                    case "*":
                    case "Ã—":
                        $val = (new Variable("input", $val1))->Multiplication($val2);
                        break;
                    case "/":
                    case "Ã·":
                        $val = (new Variable("input", $val1))->Division($val2);
                        break;
                    case "%":
                        $val = (new Variable("input", $val1))->Modulo($val2);
                        break;
                    default:
                        $val = "Â§cãã®çµ„ã¿åˆã‚ã›ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ æ¬¡ã®ä¸­ã‹ã‚‰é¸ã‚“ã§ãã ã•ã„[+|-|*|/|%]Â§r";
                        break;
                }
                ifManager::getOwner()->getVariableHelper()->add($val);
                break;
            case ifPlugin::ADD_VARIABLE:
                $datas = explode(",", $content);
                if(!isset($datas[1])){
                    $message = "Â§c[å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                    break;
                }
                ifManager::getOwner()->getVariableHelper()->add(new Variable($datas[0], $datas[1]));
                break;
            case ifPlugin::ADD_ITEM:
                $ids = explode(":", $content);
                if(!isset($ids[1]))$ids[1] = 0;
                if(!isset($ids[2]))$ids[2] = 1;
                if(!isset($ids[3])){
                    $player->getInventory()->addItem(Item::get((int)$ids[0], (int)$ids[1], (int)$ids[2]));
                    break;
                }
                $player->getInventory()->addItem(Item::get((int)$ids[0], (int)$ids[1], (int)$ids[2])->setCustomName($ids[3]));
                break;
            case ifPlugin::REMOVE_ITEM:
                $ids = explode(":", $content);
                if(!isset($ids[1]))$ids[1] == 0;
                if(isset($ids[2])){
                    $item = Item::get((int)$ids[0], (int)$ids[1], (int)$ids[2]);
                    $player->getInventory()->removeItem($item);
                    break;
                }
                $count = 0;
                foreach ($player->getInventory()->getContents() as $item) {
                    if($item->getId() == $ids[0] and $item->getDamage() == $ids[1]){
                        $count += $item->getCount();
                    }
                }
                if($count >= 1){
                    $player->getInventory()->removeItem(Item::get($ids[0], $ids[1], $count));
                }
                break;
            case ifPlugin::SET_IMMOBILE:
            	$player->setImmobile();
            	break;
            case ifPlugin::UNSET_IMMOBILE:
            	$player->setImmobile(false);
            	break;
            case ifPlugin::ADD_ENCHANTMENT:
                $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)){
		            $sender->sendMessage("ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
		            break;
		        }
		        $item = $player->getInventory()->getItemInHand();
		        $item->addEnchantment(new EnchantmentInstance($enchantment, $args[1]));
       			$player->getInventory()->setItemInHand($item);
            	break;
            case ifPlugin::ADD_EFFECT:
                $args = explode(",", $content);
                if(!isset($args[1]) or (int)$args[1] <= 0)$args[1] = 1;
                if(!isset($args[2]) or (int)$args[2] <= 0)$args[2] = 30;
        		$effect = Effect::getEffectByName($args[0]);
		        if($effect === null){
		            $effect = Effect::getEffect((int)$args[0]);
		        }
		        if($effect === null){
		            $sender->sendMessage("ã‚¨ãƒ•ã‚§ã‚¯ãƒˆãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
		            break;
		        }
		        $power = (int)$args[1];
		        $time = (int)$args[2] * 20;
				$effect = new EffectInstance($effect, $time, $power, true);
            	$player->addEffect($effect);
            	break;
            case ifPlugin::SET_NAMETAG:
            	$player->setNametag($content);
            	$player->setDisplayName($content);
            	break;
            case ifPlugin::SET_SLEEPING:
                $pos = explode(",", $content);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
		    	$pos = new Vector3((int)$pos[0], (int)$pos[1], (int)$pos[2]);
		    	$player->sleepOn($pos);
            	break;
            case ifPlugin::SET_SITTING:
                $pos = explode(",", $content);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                if(!isset($pos[3]))$pos[3] = $player->level;
		        $pk = new AddEntityPacket();
		        $pk->entityRuntimeId = Entity::$entityCount++;
		        $pk->type = 84;
		        $pk->position = new Position((int)$pos[0], (int)$pos[1], (int)$pos[2], $pos[3]);
		          $link = new EntityLink();
				  $link->riddenId = $pk->entityRuntimeId;
				  $link->riderId = $player->getId();
				  $link->type = 1;
		        $pk->links = [$link];
		        $pk->metadata = [
					Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_INVISIBLE]
				];
		        $player->dataPacket($pk);
		        break;
            case ifPlugin::SET_GAMEMODE:
            	$gamemode = Server::getGamemodeFromString($content);
            	if($gamemode === -1){
            		$player->sendMessage("ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“");
            		break;
            	}
            	$player->setGamemode($gamemode);
            	break;
            case ifPlugin::SET_HEALTH:
            	$health = (int)$content;
            	if($health <= 0)$health = 1;
            	$player->setHealth($health);
            	break;
            case ifPlugin::SET_MAXHEALTH:
            	$health = (int)$content;
            	if($health <= 0)$health = 1;
            	$player->setMaxHealth($health);
            	break;
		    case ifPlugin::ATTACK:
				$data = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_ENTITY_ATTACK, (int)$content);
				$player->attack($data);
				break;
			case ifPlugin::KICK:
		    	$player->kick($content);
		    	break;
        }
    }

    public function executeIfMatchCondition($player, $datas1, $datas2, $datas3){
        $stat = "2";
        foreach($datas1 as $datas){
            $result = $this->checkMatchCondition($player, $datas["id"], $this->replace($datas["content"]));
            if($result === self::NOT_FOUND){
                $player->sendMessage("Â§cã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸ(id: ".$datas["id"]."ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“)");
                return false;
            }elseif($result === self::NOT_MATCHED){
                $stat = "3";
            }
        }
        foreach (${"datas".$stat} as $datas) {
            $this->execute($player, $datas["id"], $this->replace($datas["content"]));
        }
        return true;
    }

    public function replace($string){
        $count = 0;
        while(preg_match_all("/({[^{}]+})/", $string, $matches)){
            if(++$count >= 10) break;
            foreach ($matches[0] as $name) {
                $val = ifManager::getOwner()->getVariableHelper()->get(substr($name, 1, -1));
                $string = str_replace($name, $val instanceof Variable ? $val->getValue(): $val, $string);
            }
        }
        return $string;
    }
}<?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\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;

class ifPlugin extends PluginBase implements Listener{

    const IF_TAKEMONEY = 0;
    const IF_HAVEINGITEM = 1;
    const IF_EXISTITEM = 2;
    const IF_IS_SNEAKING = 3;
    const IF_OVERMONEY = 4;
    const IF_REMOVEITEM = 5;
    const IF_GAMEMODE = 6;
    const IF_NO_CHECK = 7;
    const IF_COMPARISON = 8;
    const IF_IS_OP = 9;
    const IF_IS_FLYING = 10;
    const IF_IN_AREA = 11;
    const IF_RANDOM_NUMBER = 12;

    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;

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

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

        Form::registerFormIds();

        if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 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->api = new ifAPI();

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

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

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

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

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

    public function getEcomony(){
        return $this->economy;
    }

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

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

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

    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 = new EconomyLoader();
            $this->getServer()->getLogger()->warning("[if] çµŒæ¸ˆã‚·ã‚¹ãƒ†ãƒ ãƒ—ãƒ©ã‚°ã‚¤ãƒ³ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“ã§ã—ãŸ");
        }
    }
}<?php

namespace aieuo\ip\manager;

class BlockManager extends ifManager{

	public function __construct($owner){
		parent::__construct($owner ,"blocks");
		if(!file_exists($this->getDataFolder()."blocks.yml")){
	        if(file_exists($this->getDataFolder()."if.db")) {
	            $db = new \SQLite3($this->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE);
	        	$this->moveDB($db);
	        }
	    }
	}

	public function moveDB($db){
		$res = $db->query("SELECT * FROM list");
		while($row = $res->fetchArray()) {
			$data = [
				"if" => [
					["id" => $row["if"], "content" => $row["if_content"]]
				],
				"match" => [
					["id" => $row["type1"]+100, "content" => $row["type1_content"]]
				],
				"else" => [
					["id" => $row["type2"]+100, "content" => $row["type2_content"]]
				]
			];
			$this->set($row["pos"], $data);
		}
	}

    public function getPosition($block){
        return $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
    }

    public function set($key, $data = []){
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        parent::set($key, $data);
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\command\Command;
use pocketmine\command\PluginCommand;

class CommandManager extends ifManager{

    private $command_list = [];

	public function __construct($owner){
        parent::__construct($owner, "commands");
        $this->registerCommands();
	}

    public function registerCommands(){
        foreach($this->getAll() as $command => $value){
    		if($this->isSubcommand($command))$command = $this->getOriginalCommand($command);
            if(!$this->exists($command)){
                $this->register($command, $value["permission"], $value["description"]);
            }
        }
    }

    public function register($command, $permission = "default", $description = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™"){
    	if($this->isSubcommand($command))$command = $this->getOriginalCommand($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){
        if($this->isSubcommand($command))$command = $this->getOriginalCommand($command);
        if($this->exists($command) or !isset($this->command_list[$command]))return false;
        $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 getSubcommand($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 getOriginalCommand($command){
    	if(!$this->isSubcommand($command))return $command;
    	$commands = explode(" ", $command);
    	return $commands[0];
    }

    public function setOptions($command, $description, $permission){
        $this->tmp[$command] = [$description, $permission];
    }

    public function set($key, $data = []){
        if(isset($this->tmp[$key])){
            $data["description"] = $this->tmp[$key][0];
            $data["permission"] = $this->tmp[$key][1];
            unset($this->tmp[$key]);
        }
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        parent::set($key, $data);
    }

    public function add($key, $type, $id, $content){
        $datas = [];
        if($this->isAdded($key))$datas = $this->get($key);
        if(isset($this->tmp[$key])){
            $datas["description"] = $this->tmp[$key][0];
            $datas["permission"] = $this->tmp[$key][1];
            unset($this->tmp[$key]);
        }
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        if(!isset($datas["description"]))$datas["description"] = "ifPluginã§è¿½åŠ ã—ãŸã‚³ãƒžãƒ³ãƒ‰ã§ã™";
        if(!isset($datas["permission"]))$datas["permission"] = "op";
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->register($key, $datas["description"], $datas["permission"]);
        parent::set($key, $datas);
    }

    public function remove($key){
        $this->unregister($key);
        parent::remove($key);
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\Player;
use pocketmine\event\Cancellable;
use pocketmine\event\Listener;
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\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;

use aieuo\ip\ifPlugin;

class EventManager extends ifManager{

	public function __construct($owner){
        parent::__construct($owner, "events");
    }

    public function setOptions($eventname, $event = null){
        $this->tmp = [$eventname, $event];
    }

    public function get($key){
        $datass = $this->getByEvent($this->tmp[0]);
        if(!isset($datass[$key]))return [];
        $datas = $datass[$key];
        $change = false;
        foreach ($datas as $type => $data) {
            if(!is_array($data) or count($data) == 0)continue;
            if(!isset($data[0])){
                $datass[$key][$type] = [];
                foreach ($data as $key => $value) {
                    $datass[$key][$type][] = [
                        "id" => str_replace("id", "", $key),
                        "content" => $value
                    ];
                }
                $change = true;
            }
        }
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        if($change){
            $this->set($this->tmp[0], $datass);
        }
        return $datas;
    }

    public function getCount($event){
        $datas = $this->getByEvent($this->tmp[0]);
        return count($datas);
    }

    public function add_empty(){
        $datas = $this->getByEvent($this->tmp[0]);
        $data = [
            "if" => [],
            "match" => [],
            "else" => []
        ];
        $datas[] = $data;
        $this->set($this->tmp[0], $datas);
        return count($datas) -1;
    }

    public function add($key, $type, $id, $content){
        $datas = $this->getByEvent($this->tmp[0]);
        $datas[$key][$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->set($this->tmp[0], $datas);
    }

    public function getByEvent($event){
        $datas = [];
        if(isset(($all = $this->getAll())[$event]))$datas = $all[$event];
        return $datas;
    }

    public function del($key, $type, $num){
        $datas = $this->getByEvent($this->tmp[0]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key][$type][$num]);
        $datas[$key][$type] = array_merge($datas[$key][$type]);
        $this->set($this->tmp[0], $datas);
        return true;
    }

    public function remove($key){
        $datas = $this->getByEvent($this->tmp[0]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key]);
        $datas = array_merge($datas);
        $this->set($this->tmp[0], $datas);
        return true;
    }

    public function replaceVariable($event, $eventname, $mes){
        switch ($eventname) {
            case 'PlayerInteractEvent':
            case 'PlayerChatEvent':
            case 'PlayerCommandPreprocessEvent':
            case 'PlayerJoinEvent':
            case 'PlayerQuitEvent':
            case 'PlayerToggleFlightEvent':
            case 'BlockBreakEvent':
            case 'BlockPlaceEvent':
                $player = $event->getPlayer();
                break;
            case 'EntityDamageEvent':
            case 'EntityDeathEvent':
                $player = $event->getEntity();
                if(!$player instanceof Player)return $mes;
                break;
        }
        $variables["{playername}"] = $player->getName();
        $variables["{nametag}"] = $player->getDisplayName();
        $variables["{playerpos}"] = $player->x." ".$player->y." ".$player->z." ".$player->level->getFolderName();
        $variables["{player_x}"] = (int)$player->x;
        $variables["{player_y}"] = (int)$player->y;
        $variables["{player_z}"] = (int)$player->z;
        $variables["{player_level}"] = $player->level->getFolderName();
        if(
            $eventname == "PlayerInteractEvent"
            or $eventname == "BlockBreakEvent"
            or $eventname == "BlockPlaceEvent"
        ){
            $block = $event->getBlock();
            $variables["{block}"] = $block->__toString();
            $variables["{blockname}"] = $block->getName();
            $variables["{blockid}"] = $block->getId();
            $variables["{blockdamage}"] = $block->getDamage();
            $variables["{blockids}"] = $block->getId().":".$block->getDamage();
            $variables["{blockpos}"] = $block->x." ".$block->y." ".$block->z." ".$block->level->getFolderName();
            $variables["{block_level}"] = $block->level->getFolderName();
        }
        if(
            $eventname == "PlayerChatEvent"
            or $eventname == "PlayerCommandPreprocessEvent"
        ){
            $variables["{mes}"] = $event->getMessage();
        }
        if($eventname == "EntityDamageEvent"){
            $entity = $event->getEntity();
            if($event instanceof EntityDamageByEntityEvent){
                $damager = $event->getDamager();
                if($damager instanceof Player){
                    $datas["{attacker}"] = $damager->getName();
                }
            }
        }
        foreach ($variables as $variable => $value) {
            $mes = str_replace($variable, $value, $mes);
        }
        return $mes;
    }

    public function execute($player, $type, $content){
        switch ($type) {
            case ifPlugin::EVENT_CANCELL:
                $event = $this->tmp[1];
                if($event instanceof Cancellable){
                    $event->setCancelled();
                }
                return;
        }
        parent::execute($player, $type, $content);
    }

    public function executeIfMatchCondition($player, $datas1, $datas2, $datas3){
        for($i = 1; $i <= 3; $i ++){
            foreach(${"datas".$i} as $key => $datas){
                ${"datas".$i}[$key]["content"] = $this->replaceVariable($this->tmp[1], $this->tmp[0], $datas["content"]);
            }
        }
        parent::executeIfMatchCondition($player, $datas1, $datas2, $datas3);
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\utils\Config;

use aieuo\ip\ifPlugin;
use aieuo\ip\ifAPI;

class ifManager extends ifAPI{

	private static $owner;
	private $config;

	public function __construct($owner, $type){
		self::$owner = $owner;
        $this->config = new Config($this->getDataFolder() . $type. ".yml", Config::YAML, []);
	}

	public static function getOwner(){
		return self::$owner;
	}

	public function getServer(){
		return self::getOwner()->getServer();
	}

	public function getDataFolder(){
		return self::getOwner()->getDataFolder();
	}

    public function getConfig(){
        return $this->config;
    }

    public function isAdded($key){
    	return $this->config->exists($key);
    }

    public function get($key){
        if(!$this->isAdded($key))return false;
        $datas = $this->config->get($key);
        $change = false;
        foreach ($datas as $type => $data) {
            if(!is_array($data) or count($data) == 0)continue;
            if(!isset($data[0])){
                $datas[$type] = [];
                foreach ($data as $key => $value) {
                    $datas[$type][] = [
                        "id" => str_replace("id", "", $key),
                        "content" => $value
                    ];
                }
                $change = true;
            }
        }
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        if($change){
            $this->set($key, $datas);
        }
        return $datas;
    }

    public function getAll(){
    	return $this->config->getAll();
    }

    public function set($key, $datas = []){
    	$this->config->set($key, $datas);
    }

    public function del($key, $type, $num){
        if(!$this->isAdded($key))return false;
        $datas = $this->get($key);
        unset($datas[$type][$num]);
        $datas[$type] = array_merge($datas[$type]);
        $this->set($key, $datas);
        return true;
    }

    public function remove($key){
    	$this->config->remove($key);
    }

	public function save(){
		$this->config->save();
	}

    public function add($key, $type, $id, $content){
        $datas = [];
        if($this->isAdded($key))$datas = $this->get($key);
        if(!isset($datas["if"]))$datas["if"] = [];
        if(!isset($datas["match"]))$datas["match"] = [];
        if(!isset($datas["else"]))$datas["else"] = [];
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->config->set($key, $datas);
    }
}<?php

namespace aieuo\ip;

class Session {

	const BLOCK = 0;
	const COMMAND = 1;
	const EVENT = 2;

	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){
		if($type !== self::BLOCK and $type !== self::COMMAND and $type !== self::EVENT)$type = self::BLOCK;
		$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 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->getVariableHelper()->save();
	}
}<?php

namespace aieuo\ip\utils;

use aieuo\ip\ifPlugin;

class Messages {

    public static function createMessage($ifs, $matchs, $elses){
    	$mes = "ã‚‚ã—\n";
        foreach($ifs as $if){
            $mes .= self::getMessage($if["id"], $if["content"]).",\n";
        }
        $mes .= "\nãªã‚‰\n";
        foreach ($matchs as $match) {
            $mes .= self::getMessage($match["id"], $match["content"]).",\n";
        }
        $mes .= "\næ¡ä»¶ã«åˆã‚ãªã‹ã£ãŸã‚‰\n";
        foreach ($elses as $else) {
            $mes .= self::getMessage($else["id"], $else["content"]).",\n";
        }
        return $mes;
    }

	public static function getMessage($num, $value = "", $event = false){
        switch ($num){
            case ifPlugin::IF_NO_CHECK:
                $message = "ä½•ã‚‚ç¢ºèªã—ãªã„";
                break;
            case ifPlugin::IF_TAKEMONEY:
                $message = "$".$value."æ‰•ãˆã‚‹";
                break;
            case ifPlugin::IF_OVERMONEY:
                $message = "$".$value."ã‚ˆã‚Šæ‰€æŒé‡‘ãŒå¤šã„";
                break;
            case ifPlugin::IF_HAVEINGITEM:
                $message = "idãŒ".$value."ã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’æ‰‹ã«æŒã£ã¦ã‚‹";
                break;
            case ifPlugin::IF_EXISTITEM:
                $message = "idãŒ".$value."ã‚¢ã‚¤ãƒ†ãƒ ãŒã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«å…¥ã£ã¦ã„ã‚‹";
                break;
            case ifPlugin::IF_REMOVEITEM:
                $message = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰(".$value.")ã‚’å‰Šé™¤ã§ãã‚‹";
                break;
            case ifPlugin::IF_IS_OP:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒop";
                break;
            case ifPlugin::IF_IS_SNEAKING:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹";
                break;
            case ifPlugin::IF_IS_FLYING:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒé£›ã‚“ã§ã„ã‚‹";
                break;
            case ifPlugin::IF_GAMEMODE:
                $message = "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒ(".$value.")";
                break;
            case ifPlugin::IF_IN_AREA:
                preg_match("/([xyz]\(-?[0-9\.]+,-?[0-9\.]+\))+/", $value, $matches);
                array_shift($matches);
                $mes = [];
                foreach ($matches as $match) {
                    if(!preg_match("/([xyz])\((-?[0-9\.]+),-?([0-9\.]+)\)/", $match, $result))continue;
                    $min = min((float)$result[2], (float)$result[3]);
                    $max = max((float)$result[2], (float)$result[3]);
                    $mes[] = $result[1]."åº§æ¨™ãŒ".$min."ä»¥ä¸Šã€".$max."ä»¥ä¸‹";
                }
                if(count($mes) == 0){
                    $message = "Â§c[æŒ‡å®šã—ãŸç¯„å›²å†…ã«ã„ãŸã‚‰] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                }else{
                    $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒ".implode(",", $mes)."ã«ã„ã‚‹";
                }
                break;
            case ifPlugin::IF_RANDOM_NUMBER:
                if(!preg_match("/(-?[0-9]+),(-?[0-9]+);(-?[0-9]+)/", $value, $matches)){
                    $message = "Â§c[ä¹±æ•°ãŒæŒ‡å®šã—ãŸã‚‚ã®ã ã£ãŸã‚‰] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                }else{
                    $min = min((int)$matches[1], (int)$matches[2]);
                    $max = max((int)$matches[1], (int)$matches[2]);
                    $message = $min."ï½ž".$max."ã®ç¯„å›²ã®ä¹±æ•°ãŒ".$matches[3];
                }
                break;
            case ifPlugin::IF_COMPARISON:
                if(!preg_match("/([^!>=<]+)([!>=<]{1,2})([^!>=<]+)/", $value, $matches)){
                    $message = "Â§c[äºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                }else{
                    $operator = $matches[2];
                    $val1 = trim(rtrim($matches[1]));
                    $val2 = trim(rtrim($matches[3]));
                    switch ($operator){
                        case "=":
                        case "==":
                            $message = $val1."ã¨".$val2."ãŒç­‰ã—ã„";
                            break;
                        case "!=":
                        case "=!":
                            $message = $val1."ã¨".$val2."ãŒç­‰ã—ããªã„";
                            break;
                        case ">":
                            $message = $val1."ãŒ".$val2."ã‚ˆã‚Šå¤§ãã„";
                            break;
                        case "<":
                            $message = $val1."ãŒ".$val2."ã‚ˆã‚Šå°ã•ã„";
                            break;
                        case ">=":
                        case "=>":
                            $message = $val1."ãŒ".$val2."ä»¥ä¸Š";
                            break;
                        case "<=":
                        case "=<":
                            $message = $val1."ãŒ".$val2."ä»¥ä¸‹";
                            break;
                        case "><":
                            $message = $val1."ã®ä¸­ã«".$val2."ãŒå«ã¾ã‚Œã¦ã„ã‚‹";
                            break;
                        case "<>":
                            $message = $val1."ã®ä¸­ã«".$val2."ãŒå«ã¾ã‚Œã¦ã„ãªã„";
                            break;
                        default:
                            $message = "Â§cãã®çµ„ã¿åˆã‚ã›ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ æ¬¡ã®ä¸­ã‹ã‚‰é¸ã‚“ã§ãã ã•ã„[==|>|>=|<|<=|!=]Â§r";
                            break;
                    }
                }
                break;
            case ifPlugin::DO_NOTHING:
                $message = "ä½•ã‚‚ã—ãªã„";
                break;
            case ifPlugin::SENDMESSAGE:
                $message = "ãƒãƒ£ãƒƒãƒˆæ¬„ã«(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::SENDTIP:
                $message = "tipæ¬„ã«(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::SENDTITLE:
                $message = "ã‚¿ã‚¤ãƒˆãƒ«æ¬„ã«(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::BROADCASTMESSAGE:
                $message = "å…¨å“¡ã®ãƒãƒ£ãƒƒãƒˆæ¬„ã«(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::SENDMESSAGE_TO_OP:
                $message = "opã ã‘ã«(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::SENDVOICEMESSAGE:
                $message = "éŸ³å£°ä»˜ãã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸(".$value.")ã‚’é€ä¿¡ã™ã‚‹";
                break;
            case ifPlugin::COMMAND:
                $message = "ã‚³ãƒžãƒ³ãƒ‰(/".$value.")ã‚’å®Ÿè¡Œã™ã‚‹";
                break;
            case ifPlugin::COMMAND_CONSOLE:
                $message = "ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã‚³ãƒžãƒ³ãƒ‰(/".$value.")ã‚’å®Ÿè¡Œã™ã‚‹";
                break;
            case ifPlugin::DELAYED_COMMAND:
                if(!preg_match("/([0-9]+),(.+)/", $value, $matches)){
                    $player->sendMessage("Â§c[é…ã‚Œã¦ã‚³ãƒžãƒ³ãƒ‰å®Ÿè¡Œ] æ›¸ãæ–¹ãŒæ­£ã—ãã‚ã‚Šã¾ã›ã‚“Â§f");
                    break;
                }
                $message = $matches[1]."ç§’å¾Œã«/".$matches[2]."ã‚’å®Ÿè¡Œã™ã‚‹";
                break;
            case ifPlugin::TELEPORT:
                $pos = explode(",", $value);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                $message = "(".implode(",", $pos).")ã«ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹";
                break;
            case ifPlugin::MOTION:
                $pos = explode(",", $value);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                $message = "(".implode(",", $pos).")ãƒ–ãƒ­ãƒƒã‚¯åˆ†å‹•ã‹ã™";
                break;
            case ifPlugin::CALCULATION:
                if(!preg_match("/([^+ï¼‹-ãƒ¼*\/%ï¼…Ã—Ã·]+)([+ï¼‹-ãƒ¼*\/%Ã—Ã·])([^+ï¼‹-ãƒ¼*\/%Ã—Ã·]+)/", $value, $matches)){
                    $message = "Â§c[è¨ˆç®—ã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                }else{
                    $operator = $matches[2];
                    $val1 = trim(rtrim($matches[1]));
                    $val2 = trim(rtrim($matches[3]));
                    switch ($operator){
                        case "+":
                        case "ï¼‹":
                            $message = $val1."ã¨".$val2."ã‚’è¶³ã™";
                            break;
                        case "-":
                        case "ãƒ¼":
                            $message = $val1."ã‹ã‚‰".$val2."ã‚’å¼•ã";
                            break;
                        case "*":
                        case "Ã—":
                            $message = $val1."ã¨".$val2."ã‚’æŽ›ã‘ã‚‹";
                            break;
                        case "/":
                        case "Ã·":
                            $message = $val1."ã‚’".$val2."ã§å‰²ã‚‹";
                            break;
                        case "%":
                            $message = $val1."ã‚’".$val2."ã§å‰²ã£ãŸä½™ã‚Š";
                            break;
                        default:
                            $message = "Â§cãã®çµ„ã¿åˆã‚ã›ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ æ¬¡ã®ä¸­ã‹ã‚‰é¸ã‚“ã§ãã ã•ã„[+|-|*|/|%]Â§r";
                            break;
                    }
                }
                break;
            case ifPlugin::ADD_VARIABLE:
                $datas = explode(",", $value);
                if(!isset($datas[1])){
                    $message = "Â§c[å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹] æ­£ã—ãå…¥åŠ›ã§ãã¦ã„ã¾ã›ã‚“Â§f";
                    break;
                }
                $message = $datas[0]."ã¨ã„ã†åå‰ã®å¤‰æ•°(".$datas[1].")ã‚’è¿½åŠ ã™ã‚‹";
                break;
            case ifPlugin::ADD_ITEM:
                $ids = explode(":", $value);
                if(!isset($ids[1]))$ids[1] = 0;
                if(!isset($ids[2]))$ids[2] = 1;
                if(!isset($ids[3]))$ids[3] = "";
                $message = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«($ids[0]:$ids[1] x$ids[2], $ids[3])ã‚’è¿½åŠ ã™ã‚‹";
                break;
            case ifPlugin::REMOVE_ITEM:
                $ids = explode(":", $value);
                if(!isset($ids[1]))$ids[1] == 0;
                if(!isset($ids[2]))$ids[2] == "å…¨ã¦";
                $message = "ã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰($ids[0]:$ids[1] x$ids[2])ã‚’å‰Šé™¤ã™ã‚‹";
                break;
            case ifPlugin::SET_IMMOBILE:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ãªãã™ã‚‹";
                break;
            case ifPlugin::UNSET_IMMOBILE:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹";
                break;
            case ifPlugin::ADD_ENCHANTMENT:
                $args = explode(",", $value);
                if(!isset($args[1]) or (int)$args[1] <= 0)$args[1] = 1;
                $message = "æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«(id:".$args[0].",ãƒ¬ãƒ™ãƒ«:".$args[1].")ã®ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’è¿½åŠ ã™ã‚‹";
                break;
            case ifPlugin::ADD_EFFECT:
                $args = explode(",", $value);
                if(!isset($args[1]) or (int)$args[1] <= 0)$args[1] = 1;
                if(!isset($args[2]) or (int)$args[2] <= 0)$args[2] = 30;
                $time = (int)$args[2] * 20;
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã«(id:".$args[0].",å¼·ã•:".$args[1].")ã®ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’".$time."ç§’é–“ä¸Žãˆã‚‹";
                break;
            case ifPlugin::SET_NAMETAG:
                $message = "è¡¨ç¤ºã—ã¦ã„ã‚‹åå‰ã‚’(".$value.")ã«å¤‰æ›´ã™ã‚‹";
                break;
            case ifPlugin::SET_SLEEPING:
                $pos = explode(",", $value);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                $message = "(".implode(",", $pos).")ã§å¯ã‹ã›ã‚‹";
                break;
            case ifPlugin::SET_SITTING:
                $pos = explode(",", $value);
                if(!isset($pos[1]))$pos[1] = 0;
                if(!isset($pos[2]))$pos[2] = 0;
                $message = "(".implode(",", $pos).")ã§åº§ã‚‰ã›ã‚‹";
                break;
            case ifPlugin::SET_GAMEMODE:
                $message = "ã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’(".$value.")ã«è¨­å®šã™ã‚‹";
                break;
            case ifPlugin::SET_HEALTH:
                $message = "ä½“åŠ›ã‚’(".$value.")ã«è¨­å®šã™ã‚‹";
                break;
            case ifPlugin::SET_MAXHEALTH:
                $message = "æœ€å¤§ä½“åŠ›ã‚’(".$value.")ã«è¨­å®šã™ã‚‹";
                break;
            case ifPlugin::ATTACK:
                $message = "(".$value.")ãƒ€ãƒ¡ãƒ¼ã‚¸ä¸Žãˆã‚‹";
                break;
            case ifPlugin::KICK:
                $message = "(".$value.")ã§ã‚­ãƒƒã‚¯ã™ã‚‹";
                break;
            case ifPlugin::EVENT_CANCELL:
                $message = "ã‚¤ãƒ™ãƒ³ãƒˆã‚’ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";
                break;
            default:
            	$message = "";
            	break;
        }
        return $message;
    }

    public static function getFormMessage($num){
        switch ($num){
            case ifPlugin::IF_TAKEMONEY:
                $message = "ã‚‚ã—\nÂ§lãŠé‡‘ã‚’";
                $next = "Â§læ‰•ãˆã‚‹ãªã‚‰\n\n";
                $placeholder = "é‡‘é¡ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_OVERMONEY:
                $message = "ã‚‚ã—\nÂ§læ‰€æŒé‡‘ãŒ";
                $next = "Â§lã‚ˆã‚Šå¤šã„ãªã‚‰\n\n";
                $placeholder = "é‡‘é¡ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_HAVEINGITEM:
                $message = "ã‚‚ã—\nÂ§lidãŒ\nÂ§r(id:meta:æ•° ã®ã‚ˆã†ã«çŸ³ãŒ10å€‹ãªã‚‰1:0:10, æ•°ã‚’è€ƒãˆãªã„ãªã‚‰1:0)";
                $next = "Â§lã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’æ‰‹ã«æŒã£ã¦ã‚‹ãªã‚‰\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_EXISTITEM:
                $message = "ã‚‚ã—\nÂ§lidãŒ\nÂ§r(id:meta:æ•° ã®ã‚ˆã†ã«å®‰å±±å²©ãŒ3å€‹ãªã‚‰1:5:3, 1:5ã ã‘ãªã‚‰æ•°ã¯1å€‹ã«ãªã‚Šã¾ã™)";
                $next = "Â§lã®ã‚¢ã‚¤ãƒ†ãƒ ãŒã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«ã‚ã‚‹ãªã‚‰\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_REMOVEITEM:
                $message = "ã‚‚ã—\nÂ§lã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰idãŒ\nÂ§r(id:meta:æ•° ã®ã‚ˆã†ã«é»„è‰²ã®ç¾Šæ¯›ãŒ2å€‹ãªã‚‰35:4:2 , 35:4ã ã‘ãªã‚‰æŒã£ã¦ã‚‹æ•°ã™ã¹ã¦)";
                $next = "Â§lã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’å‰Šé™¤ã§ãã‚‹ãªã‚‰\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_GAMEMODE:
                $message = "ã‚‚ã—\nÂ§lã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ãŒ\nÂ§r(0,1,2,3,s,c,a,v)";
                $next = "Â§lãªã‚‰\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã‹ã‚‰ä¸€ã¤é¸ã‚“ã§å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_IN_AREA:
                $message = "ã‚‚ã—\nÂ§lãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ãŒ\nÂ§r(æ›¸ãæ–¹: <x|y|z>(<æœ€å°ã®åº§æ¨™>,<æœ€å¤§ã®åº§æ¨™>)\nxåº§æ¨™ãŒ0~10ã®ç¯„å›²ãªã‚‰:  x(0,10)\nx,y,zåº§æ¨™ãŒ0~5ã®ç¯„å›²ãªã‚‰:  x(0,5)y(0,5)z(0,5))";
                $next = "Â§lã®ç¯„å›²ã«ã„ãŸã‚‰\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::IF_RANDOM_NUMBER:
                $message = "ã‚‚ã—\nÂ§lä¹±æ•°\nÂ§r(æœ€å°å€¤,æœ€å¤§å€¤;ç¢ºèªã™ã‚‹æ•°)\n1~10ã®ç¯„å›²ã®ä¹±æ•°ãŒ2ã®æ™‚ã«å‡¦ç†ã™ã‚‹ãªã‚‰:  1,10;2";
                $next = "Â§lãªã‚‰\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«å…¥åŠ›ã—ã¦ãã ã•ã„";
            case ifPlugin::IF_COMPARISON:
                $message = "ã‚‚ã—\nÂ§läºŒã¤ã®å€¤ã‚’æ¯”è¼ƒã—ã¦æ¡ä»¶ã‚’æº€ãŸã—ã¦ã„ã‚‹\nÂ§r(å€¤1 [== | > | < | >= | <= | !=])\nã‚¤ãƒ™ãƒ³ãƒˆã®ãƒ–ãƒ­ãƒƒã‚¯ã‚’è§¦ã£ãŸã¨ãã«ãƒ–ãƒ­ãƒƒã‚¯ã®idãŒ1ã‹èª¿ã¹ã‚‹ãªã‚‰:  {blockid}==1";
                $next = "Â§lãªã‚‰\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SENDMESSAGE:
                $message = "Â§lãƒãƒ£ãƒƒãƒˆæ¬„ã«";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SENDTIP:
                $message = "Â§ltipæ¬„ã«";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SENDTITLE:
                $message = "Â§ltitleæ¬„ã«";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::BROADCASTMESSAGE:
                $message = "Â§lå…¨å“¡ã®ãƒãƒ£ãƒƒãƒˆæ¬„ã«";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SENDMESSAGE_TO_OP:
                $message = "Â§lopã ã‘ã«";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SENDVOICEMESSAGE:
                $message = "Â§lãƒãƒ£ãƒƒãƒˆæ¬„ã«éŸ³å£°ä»˜ãã®";
                $next = "Â§lã‚’é€ä¿¡ã™ã‚‹\n\n";
                $placeholder = "é€ä¿¡ã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::COMMAND:
                $message = "Â§lã‚³ãƒžãƒ³ãƒ‰";
                $next = "Â§lã‚’å®Ÿè¡Œã™ã‚‹\n\n";
                $placeholder = "ã‚³ãƒžãƒ³ãƒ‰ã‚’æœ€åˆã®/ã‚’å¤–ã—ã¦å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::COMMAND_CONSOLE:
                $message = "Â§lã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã‚³ãƒžãƒ³ãƒ‰";
                $next = "Â§lã‚’å®Ÿè¡Œã™ã‚‹\n\n";
                $placeholder = "ã‚³ãƒžãƒ³ãƒ‰ã‚’æœ€åˆã®/ã‚’å¤–ã—ã¦å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::DELAYED_COMMAND:
                $message = "Â§l?ç§’å¾Œã«ã‚³ãƒžãƒ³ãƒ‰\nÂ§r(ç§’æ•°, ã‚³ãƒžãƒ³ãƒ‰)\n10ç§’å¾Œã« /aieuo ã‚’å®Ÿè¡Œã™ã‚‹ãªã‚‰: 10,aieuo";
                $next = "Â§lã‚’å®Ÿè¡Œã™ã‚‹\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::TELEPORT:
                $message = "(0,0,0,world  ã®ã‚ˆã†ã«,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã«ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«åº§æ¨™ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::MOTION:
                $message = "(0,1,0  ã®ã‚ˆã†ã«,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã«ãƒ†ãƒ¬ãƒãƒ¼ãƒˆã™ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«åº§æ¨™ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::CALCULATION:
                $message = "Â§läºŒã¤ã®å€¤ã‚’è¨ˆç®—ã™ã‚‹\nÂ§r(+ | - | * | / | %)";
                $next = "Â§l\n\n";
                $placeholder = "ã‚«ãƒƒã‚³å†…ã®æ¼”ç®—å­ã‚’ä½¿ç”¨ã§ãã¾ã™";
                break;
            case ifPlugin::ADD_VARIABLE:
                $message = "Â§lå¤‰æ•°\nÂ§r(åå‰,å€¤  \n  aieuoã¨ã„ã†åå‰ã§å€¤ãŒ100ã®å¤‰æ•°ã‚’è¿½åŠ ã™ã‚‹ãªã‚‰:   aieuo,100)";
                $next = "Â§lã‚’è¿½åŠ ã™ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::ADD_ITEM:
                $message = "Â§lã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã«idãŒ\nÂ§r(id:meta:æ•° ,åå‰ã‚’ä»˜ã‘ã‚‹ãªã‚‰id:meta:æ•°:åå‰ ã®ã‚ˆã†ã«)";
                $next = "Â§lã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’è¿½åŠ ã™ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::REMOVE_ITEM:
                $message = "Â§lã‚¤ãƒ³ãƒ™ãƒ³ãƒˆãƒªã‹ã‚‰idãŒ\nÂ§r(id:meta:æ•° æ•°ã‚’å…¥ã‚Œãªã‹ã£ãŸã‚‰æŒã£ã¦ã‚‹æ•°ã™ã¹ã¦)";
                $next = "Â§lã®ã‚¢ã‚¤ãƒ†ãƒ ã‚’å‰Šé™¤ã™ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«idã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::ADD_ENCHANTMENT:
                $message = "Â§lid,ãƒ¬ãƒ™ãƒ«ãŒ\nÂ§r(,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã®ã‚¨ãƒ³ãƒãƒ£ãƒ³ãƒˆã‚’æ‰‹ã«æŒã£ã¦ã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã«è¿½åŠ ã™ã‚‹\n\n";
                $placeholder = "æ•°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::ADD_EFFECT:
                $message = "Â§lid,å¼·ã•,æ™‚é–“ãŒ\nÂ§r(,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã®ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚’ä¸Žãˆã‚‹\n\n";
                $placeholder = "æ•°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_NAMETAG:
                $message = "Â§lè¡¨ç¤ºã—ã¦ã„ã‚‹åå‰ã‚’";
                $next = "Â§lã«ã™ã‚‹\n\n";
                $placeholder = "ã‹ã£ã“ã®ä¸­ã‹ã‚‰ä¸€ã¤é¸ã‚“ã§å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_SLEEPING:
                $message = "(0,0,0,world  ã®ã‚ˆã†ã«,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã§å¯ã‹ã›ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«åº§æ¨™ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_SITTING:
                $message = "(0,0,0,world  ã®ã‚ˆã†ã«,ã§åŒºåˆ‡ã£ã¦)";
                $next = "Â§lã§åº§ã‚‰ã›ã‚‹\n\n";
                $placeholder = "ä¸Šã®ã‚«ãƒƒã‚³å†…ã®ã‚ˆã†ã«åº§æ¨™ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_GAMEMODE:
                $message = "Â§lã‚²ãƒ¼ãƒ ãƒ¢ãƒ¼ãƒ‰ã‚’\nÂ§r(0,1,2,3,s,c,a,v)";
                $next = "Â§lã«ã™ã‚‹\n\n";
                $placeholder = "ã‹ã£ã“ã®ä¸­ã‹ã‚‰ä¸€ã¤é¸ã‚“ã§å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_HEALTH:
                $message = "Â§lä½“åŠ›ã‚’\nÂ§r(2ã§ãƒãƒ¼ãƒˆä¸€å€‹åˆ†)";
                $next = "Â§lã«ã™ã‚‹\n\n";
                $placeholder = "æ•°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::SET_MAXHEALTH:
                $message = "Â§læœ€å¤§ä½“åŠ›ã‚’\nÂ§r(2ã§ãƒãƒ¼ãƒˆä¸€å€‹åˆ†)";
                $next = "Â§lã«ã™ã‚‹\n\n";
                $placeholder = "æ•°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::ATTACK:
                $message = "Â§l\nÂ§r(2ã§ãƒãƒ¼ãƒˆä¸€å€‹åˆ†)";
                $next = "Â§lãƒ€ãƒ¡ãƒ¼ã‚¸ä¸Žãˆã‚‹\n\n";
                $placeholder = "æ•°å€¤ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
            case ifPlugin::KICK:
                $message = "";
                $next = "Â§lã§ã‚­ãƒƒã‚¯ã™ã‚‹\n\n";
                $placeholder = "ç†ç”±ã‚’å…¥åŠ›ã—ã¦ãã ã•ã„";
                break;
        }
        if(isset($message))return [
        	"type" => "input",
            "message" => $message,
            "next" => $next,
            "placeholder" => $placeholder
        ];
        switch ($num){
            case ifPlugin::IF_NO_CHECK:
                $message = "ä½•ã‚‚ç¢ºèªã—ãªã„";
                break;
            case ifPlugin::IF_IS_OP:
                $message = "ã‚‚ã—\nOPãªã‚‰";
                break;
            case ifPlugin::IF_IS_SNEAKING:
                $message = "ã‚‚ã—\nã‚¹ãƒ‹ãƒ¼ã‚¯ã—ã¦ã„ã‚‹ãªã‚‰";
                break;
            case ifPlugin::IF_IS_SNEAKING:
                $message = "ã‚‚ã—\né£›ã‚“ã§ã„ã‚‹ãªã‚‰";
                break;
            case ifPlugin::DO_NOTHING:
                $message = "ä½•ã‚‚ã—ãªã„";
                break;
            case ifPlugin::SET_IMMOBILE:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ãªã„ã‚ˆã†ã«ã™ã‚‹";
                break;
            case ifPlugin::UNSET_IMMOBILE:
                $message = "ãƒ—ãƒ¬ã‚¤ãƒ¤ãƒ¼ã‚’å‹•ã‘ã‚‹ã‚ˆã†ã«ã™ã‚‹";
                break;
            case ifPlugin::EVENT_CANCELL:
                $message = "ã‚¤ãƒ™ãƒ³ãƒˆã‚’ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã™ã‚‹";
                break;
        }
        return [
        	"type" => "label",
            "message" => $message,
            "next" => "\n"
        ];
    }
}<?php

namespace aieuo\ip\variable;

class Variable {

	const STRING_VARIABLE = 0;
	const INTEGER_VARIABLE = 1;
	const ARRAY_VARIABLE = 2;

	public function __construct($name, $value, $type = VariableHelper::STRING_VARIABLE){
		$this->name = $name;
		$this->value = $value;
		$this->type = $type;
	}

	public function getName(){
		return $this->name;
	}

	public function getValue(){
		return $this->value;
	}

	public function getType(){
		return $this->type;
	}

	public function Addition($value){
		if(is_numeric($this->getValue()) and is_numeric($value)){
			$result = (int)$this->getValue() + (int)$value;
		}else{
			$result = $this->getValue().$value;
		}
		return new Variable("result", $result);
	}

	public function Subtraction($value){
		if(is_numeric($this->getValue()) and is_numeric($value)){
			$result = (int)$this->getValue() - (int)$value;
		}else{
			$result = str_replace($value, "", $value);
		}
		return new Variable("result", $result);
	}

	public function Multiplication($value){
		if(is_numeric($this->getValue()) and is_numeric($value)){
			$result = (int)$this->getValue() * (int)$value;
		}elseif(is_numeric($this->getValue())){
			$result = str_repeat($value, abs((int)$this->getValue()));
		}elseif(is_numeric($value)){
			$result = str_repeat($this->getValue(), abs((int)$value));
		}else{
			$result = "Â§cæŽ›ã‘ç®—ã§ãã¾ã›ã‚“";
		}
		return new Variable("result", $result);
	}

	public function Division($value){
		if(is_numeric($this->getValue()) and is_numeric($value)){
			if((int)$value == 0){
				$result = "Â§c0ã§å‰²ã‚Œã¾ã›ã‚“";
			}else{
				$result = (int)$this->getValue() / (int)$value;
			}
		}else{
			$result = "Â§cå‰²ã‚Šç®—ã§ãã¾ã›ã‚“";
		}
		return new Variable("result", $result);
	}

	public function Modulo($value){
		if(is_numeric($this->getValue()) and is_numeric($value)){
			$result = (int)$this->getValue() % (int)$value;
		}else{
			$result = "Â§cæ•°å­—ã§ã¯ã‚ã‚Šã¾ã›ã‚“";
		}
		return new Variable("result", $result);
	}
}<?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){
        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
	 * @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
	 * @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 new Variable($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;
		}
		$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]);
			return true;
		}
		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 = [];
	}
}G·L$qcßú¢ob›	sdÑj„‰ù   GBMB