<?php echo "Altay plugin if v2\nThis file has been generated using Turanic at Tue, 04 Sep 2018 19:43:39 +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(); ?>
‘             ø   a:9:{s:4:"name";s:2:"if";s:7:"version";s:1:"2";s:4:"main";s:14:"aieuo\ifPlugin";s:3:"api";a:1:{i:0;s:5:"3.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:1536057819;}
   plugin.ymlÂ   ÛaŽ[Â   Ӑ	¶         src/aieuo/ifAPI.phpK:  ÛaŽ[K:  OJÚ¶         src/aieuo/ifPlugin.phpŸm  ÛaŽ[Ÿm  ²p¶      name: if
main: aieuo\ifPlugin
version: 2.0
api: [3.0.0]
load: POSTWORLD
author: aieuo
commands:
 if:
  description: "もしならする"
  usage: "usage /if <add | del | check>"
  permission: op<?php

namespace aieuo;

use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;

class ifAPI{

	public function getMessage($num, $value){
        switch ($num){
                case ifPlugin::IF_TAKEMONEY:
                    $message = "$".$value."払える";
                    break;
                case ifPlugin::IF_HAVEINGITEM:
                    $message = "idが".$value."のアイテムを手に持ってる";
                    break;
                case ifPlugin::IF_EXISTITEM:
                    $message = "idが".$value."アイテムがインベントリに入っている";
                    break;
                case ifPlugin::IF_ISSNEAKING:
                    $message = "スニークしている";
                    break;
                case ifPlugin::IF_OVERMONEY:
                    $message = "$".$value."より所持金が多い";
                    break;
                case ifPlugin::IF_REMOVEITEM:
                    $message = "インベントリから(".$value.")を削除できる";
                    break;
                case ifPlugin::COMMAND:
                    $message = "コマンド(/".$value.")を実行する";
                    break;
                case ifPlugin::SENDMESSAGE:
                    $message = "チャット欄に(".$value.")を送信する";
                    break;
                case ifPlugin::SENDTIP:
                    $message = "tip欄に(".$value.")を送信する";
                    break;
                case ifPlugin::TELEPORT:
                    $message = "(".$value.")にテレポートする";
                    break;
                case ifPlugin::BROADCASTMESSAGE:
                    $message = "全員のチャット欄に(".$value.")を送信する";
                    break;
                case ifPlugin::COMMAND_CONSOLE:
                    $message = "コンソールからコマンド(/".$value.")を実行する";
                    break;
                case ifPlugin::DO_NOTHING:
                    $message = "何もしない";
                    break;
                case ifPlugin::ADD_ITEM:
                    $message = "インベントリに(".$value.")を追加する";
                    break;
                case ifPlugin::REMOVE_ITEM:
                    $message = "インベントリから(".$value.")を削除する";
                    break;
                default:
                	$message = "";
                	break;
        }
        return $message;
    }


////form////
    public function sendForm($player, $data, $id){
        $pk = new ModalFormRequestPacket();
        $pk->formId = $id;
        $pk->formData = $data;
        $player->dataPacket($pk);
    }

    public function getaddIfForm(){
        $data = [
            "type" => "custom_form",
            "title" => "追加",
            "content" => [
    			$this->getIflistDropdown(),
    			$this->getExelistDropdown(),
    			$this->getExelistDropdown()
    		]
        ];
        $json = $this->encodeJson($data);
        return $json;
    }

    public function getIflistDropdown(){
    	return [
            "type" => "dropdown",
            "text" => "もし～なら",
            "options" => [
                "お金を減らす",
                "指定したアイテムを手に持ってるか",
                "インベントリに指定したアイテムが入ってるか",
                "スニークしているか",
                "指定した金額より所持金が多いか",
                "指定したアイテムがインベントリにあるなら削除する"
            ],
            "defaultOptionIndex" => "お金を減らす"
        ];
    }

    public function getExelistDropdown(){
    	return [
            "type" => "dropdown",
            "text" => "条件に当てはまったら～をする",
            "options" => [
                "コマンドを実行する",
                "チャット欄にメッセージ送信",
                "tip欄にメッセージ送信",
                "テレポート",
                "全体にメッセージ送信",
                "コンソールからコマンド実行",
                "何もしない",
                "インベントリにアイテムを追加する",
                "インベントリからアイテムを削除する"
            ],
            "defaultOptionIndex" => "コマンドを実行する"
        ];
    }


    public function getAddForm($type){
    	if($type == "if"){
    		$type = "If";
    	}else{
    		$type = "Exe";
    	}
        $data = [
            "type" => "custom_form",
            "title" => "追加",
            "content" => [
    			$this->{"get".$type."listDropdown"}(),
    			$this->getInput("値を入力して下さい")
    		]
        ];
        $json = $this->encodeJson($data);
        return $json;
    }


    public function createIfContentForm($type1, $type2, $type3){
        $messages1 = $this->getFormMessage($type1);//もし
        $messages2 = $this->getFormMessage($type2);//合ったら
        $messages3 = $this->getFormMessage($type3);//合わなかったら

        if($messages1["type"] == "input"){
            $input1 = $this->getInput($messages1["message"], $messages1["placeholder"]);
        }else{
            $input1 = $this->getLabel($messages1["message"]);
        }
        if($messages2["type"] == "input"){
            $input2 = $this->getInput($messages1["next"].$messages2["message"], $messages2["placeholder"]);
        }else{
            $input2 = $this->getLabel($messages2["message"]);
        }
        if($messages3["type"] == "input"){
            $input3 = $this->getInput($messages2["next"]."合わなかったら\n".$messages3["message"], $messages3["placeholder"]);
        }else{
            $input3 = $this->getLabel("合わなかったら\n".$messages3["message"]);
        }

        $content[] = $input1;
        $content[] = $input2;
        $content[] = $input3;

        $content[] = $this->getLabel($messages3["next"]);

        $form = [
            "type" => "custom_form",
            "title" => "ifPlugin",
            "content" => $content
        ];
        $json = $this->encodeJson($form);
        return $json;
    }


    public function getAddCommandForm(){
        $data = [
            "type" => "custom_form",
            "title" => "追加",
            "content" => [
            	$this->getInput("追加するコマンドの名前", "最初の/を外して"),
            	$this->getInput("コマンドの説明"),
            	$this->getDropdown("権限", ["opだけ", "全員使える"], "全員使える")
            ]
        ];
        $json = $this->encodeJson($data);
        return $json;
    }


    public function getFormMessage($num){
        switch ($num){
            case ifPlugin::IF_TAKEMONEY:
                $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_OVERMONEY:
                $message = "もし\n§l所持金が";
                $next = "§lより多いなら\n\n";
                $placeholder = "金額を入力してください";
                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::COMMAND:
                $message = "§lコマンド";
                $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::TELEPORT:
                $message = "(".$value.")にテレポートする";
                $message = "(0,0,0,world  のように,で区切って)";
                $next = "§lにテレポートする\n\n";
                $placeholder = "上のカッコ内のように座標を入力してください";
                break;
            case ifPlugin::BROADCASTMESSAGE:
                $message = "§l全員のチャット欄に";
                $next = "§lを送信する\n\n";
                $placeholder = "送信するメッセージを入力してください";
                break;
            case ifPlugin::COMMAND_CONSOLE:
                $message = "§lコンソールからコマンド";
                $next = "§lを実行する\n\n";
                $placeholder = "コマンドを最初の/を外して入力してください";
                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::IF_ISSNEAKING:
                $message = "もし\nスニークしているなら";
		        return [
                	"type" => "label",
		            "message" => $message,
		            "next" => "\n"
		        ];
                break;
            case ifPlugin::DO_NOTHING:
                $message = "何もしない";
		        return [
                	"type" => "label",
		            "message" => $message,
		            "next" => "\n"
		        ];
                break;
        }
        return [
        	"type" => "input",
            "message" => $message,
            "next" => $next,
            "placeholder" => $placeholder
        ];
    }


    public function getEditCommandForm($datas){
    	$mes = "もし\n";
        foreach($datas["if"] as $if => $content){
            $id = str_replace("id", "", $if);
            $mes .= $this->getMessage($id, $content).",\n";
        }
        $mes .= "なら\n\n";
        foreach ($datas["match"] as $type => $content) {
            $id = str_replace("id", "", $type);
            $mes .= $this->getMessage($id, $content).",\n";
        }
        $mes .= "をする\n\n条件に合わなかったら\n";
        foreach ($datas["else"] as $type => $content) {
            $id = str_replace("id", "", $type);
            $mes .= $this->getMessage($id, $content).",\n";
        }
        $mes .= "をする\n";
        $data = [
        	"type" => "form",
        	"title" => "コマンドの編集",
        	"content" => $mes,
        	"buttons" => [
        		[
        			"text" => "もし~を編集する"
        		],
        		[
        			"text" => "条件に合った時を編集する",
        		],
        		[
        			"text" => "条件に合わなかった時を編集する"
        		]
        	]
        ];
        $json = $this->encodeJson($data);
        return $json;
    }

    public function getEditForm($datas){
        $data = [
        	"type" => "form",
        	"title" => "コマンドの編集",
        	"content" => "",
        	"buttons" => []
        ];
    	foreach ($datas as $key => $value) {
            $id = str_replace("id", "", $key);
            $data["buttons"][] = ["text" => $this->getMessage($id, $value)];
    	}
        $data["buttons"][] = ["text" => "追加する(既に追加してる条件を追加すると上書きされます)"];
        $json = $this->encodeJson($data);
        return $json;
    }

    public function getDelForm($id, $content){
        $data = [
            "type" => "custom_form",
            "title" => "追加",
            "content" => [
            	$this->getLabel($this->getMessage($id, $content)),
            	$this->getToggle("削除する")
            ]
        ];
        $json = $this->encodeJson($data);
        return $json;
    }

//elements//
    public function getInput($text, $placeholder = ""){
        return [
            "type" => "input",
            "text" => $text,
            "placeholder" => $placeholder
        ];
    }

    public function getLabel($text){
        return [
            "type" => "label",
            "text" => $text
        ];
    }

    public function getToggle($text){
        return [
            "type" => "toggle",
            "text" => $text
        ];
    }

    public function getDropdown($text, $options, $default){
    	return [
            "type" => "dropdown",
            "text" => $text,
            "options" => $options,
            "defaultOptionIndex" => $default
        ];
    }


    public function encodeJson($data){
        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE);
        return $json;
    }
}<?php
namespace aieuo;

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;

class ifPlugin extends PluginBase implements Listener{

    const IF_TAKEMONEY = 0;
    const IF_HAVEINGITEM = 1;
    const IF_EXISTITEM = 2;
    const IF_ISSNEAKING = 3;
    const IF_OVERMONEY = 4;
    const IF_REMOVEITEM = 5;

    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;

	public function onEnable(){
        $this->getServer()->getPluginManager()->registerEvents($this,$this);
        if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0721, true);
        if(!file_exists($this->getDataFolder()."if.db")) {
            $this->db = new \SQLite3($this->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
        }else{
            $this->db = new \SQLite3($this->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE);
        }
        $this->db->query("CREATE TABLE IF NOT EXISTS list (pos TEXT,if INT,if_content TEXT,type1 INT,type1_content TEXT,type2 INT,type2_content TEXT)");
        $this->commands = new Config($this->getDataFolder() . "commands.yml", Config::YAML, []);

        if(($this->EconomyAPI = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")) !== null){
            $this->getServer()->getLogger()->info("[if] EconomyAPIを読み込みました");
        }
        if(($this->PocketMoney = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null){
            $this->getServer()->getLogger()->info("[if] PocketMoneyを読み込みました");
        }

        $this->registerCommands();
        $this->api = new ifAPI($this);

        $this->ids = [
            "addIfForm" => mt_rand(1, 999999999),
        ];
        $this->addIfId = mt_rand(1, 999999999);
        $this->inputIfId = mt_rand(1, 999999999);
        $this->addCommandId = mt_rand(1, 999999999);
        $this->editCommandId = mt_rand(1, 999999999);
        $this->editId = mt_rand(1, 999999999);
        $this->delId = mt_rand(1, 999999999);
        $this->addId = mt_rand(1, 999999999);
    }

    public function onDisable(){
        $this->commands->save();
    }

    public function onCommand(CommandSender $sender, Command $command,string $label, array $args):bool{
        if($command->getName() == "if"){
            if(!isset($args[0]))return false;
            $name = $sender->getName();
            switch ($args[0]) {
                case 'add':
                    $form = $this->api->getaddIfForm();
                    $this->api->sendForm($sender, $form, $this->addIfId);
                    $this->type[$name] ="block";
                    break;
                case 'del':
                    $this->tap[$name] = ["type" => "del"];
                    $sender->sendMessage("ブロックをタッチしてください");
                    break;
                case 'check':
                    $this->tap[$name] = ["type" => "check"];
                    $sender->sendMessage("ブロックをタッチしてください");
                    break;
                case 'command':
                    if(!isset($args[1])){
                        $sender->sendMessage("/if command <add | del>");
                        return true;
                    }
                    switch ($args[1]) {
                        case 'add':
                            $form = $this->api->getAddCommandForm();
                            $this->api->sendForm($sender, $form, $this->addCommandId);
                            $this->type[$name] ="command";
                            break;
                        case 'del':
                            if(!isset($args[2])){
                                $sender->sendMessage("/if command del <command>");
                                return true;
                            }
                            if(!$this->commands->exists($args[2])){
                                $sender->sendMessage("そのコマンドは追加されていません");
                                return true;
                            }
                            $this->getServer()->getCommandMap()->unregister(new PluginCommand($args[2], $this));
                            $this->commands->remove($args[2]);
                            $sender->sendMessage("削除しました");
                            break;
                        case 'edit':
                            if(!isset($args[2])){
                                $sender->sendMessage("/if command edit <command>");
                                return true;
                            }
                            if(!$this->commands->exists($args[2])){
                                $sender->sendMessage("そのコマンドは追加されていません");
                                return true;
                            }
                            $datas = $this->commands->get($args[2]);
                            $form = $this->api->getEditCommandForm($datas);
                            $this->api->sendForm($sender, $form, $this->editCommandId);
                            $this->editCmd[$name] = [
                                "command" => $args[2]
                            ];
                            break;
                        case 'list':
                            $sender->sendMessage("追加しているコマンド");
                            foreach($this->commands->getAll() as $cmd => $value){
                                $sender->sendMessage($cmd.": ".$value["description"]);
                            }
                            break;
                    }
                    break;
            }
            return true;
        }
        if($this->commands->exists($command->getName())){
            $datas = $this->commands->get($command->getName());
            $stat = "match";
            foreach($datas["if"] as $if => $content){
                $id = str_replace("id", "", $if);
                $result = $this->checkMatchCondition($sender, $id, $content);
                if($result === 0){
                    $sender->sendMessage("§cエラーが発生しました(id: ".$id."が見つかりません)");
                    return true;
                }elseif($result === 2){
                    $stat = "else";
                }
            }
            foreach ($datas[$stat] as $type => $content) {
                $id = str_replace("id", "", $type);
                $this->execute($sender, $id, $content);
            }
        }
        return true;
    }

    public function onTouch(PlayerInteractEvent $event){
        $player = $event->getPlayer();
        $block = $event->getBlock();
        if(isset($this->tap[$player->getName()]["type"]) and $block->getId() !== 0){
            switch ($this->tap[$player->getName()]["type"]) {
                case 'add':
                    $pos = $this->getPosition($block);
                    $type = $this->tap[$player->getName()]["data"];
                    $contents = $this->tap[$player->getName()]["contents"];
                    $this->addIf($pos, $type[0], $contents[0], $type[1], $contents[1], $type[2], $contents[2]);
                    $player->sendMessage("追加しました");
                    break;
                case 'del':
                    $pos = $this->getPosition($block);
                    if(!$this->isIfBlock($pos)){
                        $player->sendMessage("そのブロックには追加されていません");
                        return;
                    }
                    $this->delIf($pos);
                    $player->sendMessage("削除しました");
                    break;
                case 'check':
                    $pos = $this->getPosition($block);
                    if(!$this->isIfBlock($pos)){
                        $player->sendMessage("そのブロックには追加されていません");
                        return;
                    }
                    $data = $this->getIf($pos);
                    $player->sendMessage("もし".$this->api->getMessage($data["if"], $data["if_content"])."なら、".$this->api->getMessage($data["type1"]+100, $data["type1_content"])."\n条件に合わなかったら".$this->api->getMessage($data["type2"]+100, $data["type2_content"]));
                    break;
            }
            unset($this->tap[$player->getName()]);
            return;
        }
        if($block->getId() === 0)return;
        if($this->isIfBlock($this->getPosition($block))){
            $data = $this->getIf($this->getPosition($block));
            $name = $player->getName();
            $this->executeIfMatchCondition($player, $data["if"], $data["if_content"], $data["type1"]+100, $data["type1_content"], $data["type2"]+100, $data["type2_content"]);
        }
    }

    public function Receive(DataPacketReceiveEvent $event){
        $pk = $event->getPacket();
        $player = $event->getPlayer();
        $name = $player->getName();
        if($pk instanceof ModalFormResponsePacket){
            if($pk->formId === $this->addIfId){
                $data = json_decode($pk->formData);
                if($pk->formData === null) {
                   return;
                }
                $form = $this->api->createIfContentForm($data[0], $data[1] + 100, $data[2] + 100);
                $this->api->sendForm($player, $form, $this->inputIfId);
                if($this->type[$name] == "block"){
                    $this->tap[$name] = [
                        "type" => "add",
                        "data" => $data
                    ];
                    return;
                }

                for($i = 2; $i >= 0; $i--){
                    $this->addCmd[$name]["content"][$i] = "";
                    $this->addCmd[$name]["type"][$i] = $data[$i];
                    if($i == 0)break;
                    $this->addCmd[$name]["type"][$i] += 100;
                }

            }elseif($pk->formId === $this->inputIfId){
                $data = json_decode($pk->formData);
                if($pk->formData === null) {
                   return;
                }
                if($this->type[$name] == "block"){
                    $datas = $this->tap[$name];
                    if(
                        ($datas["data"][0] !== self::IF_ISSNEAKING and $data[0] == "")
                        or ($datas["data"][1]+100 !== self::DO_NOTHING and $data[1] == "")
                        or ($datas["data"][2]+100 !== self::DO_NOTHING and $data[2] == "")
                    ){
                        $player->sendMessage("必要事項を記入してください");
                        return true;
                    }
                    if($datas["data"][0] == self::IF_ISSNEAKING)$data[0] = "null";
                    if($datas["data"][1]+100 == self::DO_NOTHING)$data[1] = "null";
                    if($datas["data"][2]+100 == self::DO_NOTHING)$data[2] = "null";
                    $this->tap[$name]["contents"] = $data;
                    $player->sendMessage("追加するブロックを触ってください");
                }else{
                    $datas = $this->addCmd[$name];
                    if(
                        ($datas["type"][0] !== self::IF_ISSNEAKING and $data[0] == "")
                        or ($datas["type"][1]+100 !== self::DO_NOTHING and $data[1] == "")
                        or ($datas["type"][2]+100 !== self::DO_NOTHING and $data[2] == "")
                    ){
                        $player->sendMessage("必要事項を記入してください");
                        return true;
                    }
                    $add = [
                        "if" => [
                            "id".$datas["type"][0] => (string)$data[0]
                        ],
                        "match" => [
                            "id".$datas["type"][1] => (string)$data[1]
                        ],
                        "else" => [
                            "id".$datas["type"][2] => (string)$data[2]
                        ]
                    ];
                    $this->addCommand($datas["command"], $add);
                    $this->registerCommand($datas["command"]);
                }

            }elseif($pk->formId === $this->addCommandId){
                $data = json_decode($pk->formData);
                if($pk->formData === null) {
                   return;
                }
                if($data[0] == ""){
                    $player->sendMessage("必要事項を記入してください");
                    return true;
                }
                if($this->existCommand($data[0])){
                    $player->sendMessage("§eそのコマンドは既に使用されています");
                    return true;
                }
                if($data[1] == "")$data[1] = null;
                if($data[2] == 0){
                    $permission = "op";
                }else{
                    $permission = "default";
                }
                $this->registerCommand($data[0], $permission, $data[1]);
                $this->addCommand($data[0], null, $permission, $data[1]);
                $this->addCmd[$name] = [
                    "command" => $data[0]
                ];
                $form = $this->api->getaddIfForm();
                $this->api->sendForm($player, $form, $this->addIfId);

            }elseif($pk->formId === $this->editCommandId){
                $data = json_decode($pk->formData);
                if($pk->formData === null or $data === null) {
                   return;
                }
                $datas = $this->commands->get($this->editCmd[$name]["command"]);
                if($data == 0){
                    $form = $this->api->getEditForm($datas["if"]);
                    $this->editCmd[$name]["type"] = "if";
                }elseif($data == 1){
                    $form = $this->api->getEditForm($datas["match"]);
                    $this->editCmd[$name]["type"] = "match";
                }else{
                    $form = $this->api->getEditForm($datas["else"]);
                    $this->editCmd[$name]["type"] = "else";
                }
                $this->api->sendForm($player, $form, $this->editId);

            }elseif($pk->formId === $this->editId){
                $data = json_decode($pk->formData);
                if($pk->formData === null or $data === null){
                   return;
                }
                $datas = $this->commands->get($this->editCmd[$name]["command"])[$this->editCmd[$name]["type"]];
                if($data == count($datas)){
                    $form = $this->api->getAddForm($this->editCmd[$name]["type"]);
                    $this->api->sendForm($player, $form, $this->addId);
                }else{
                    $detail = array_slice($datas, $data, 1, true);
                    $id = key($detail);
                    if($this->editCmd[$name]["type"] != "if")$id += 100;
                    $form = $this->api->getDelForm(key($detail), current($detail));
                    $this->api->sendForm($player, $form, $this->delId);
                    $this->editCmd[$name]["num"] = $data;
                }

            }elseif($pk->formId === $this->delId){
                $data = json_decode($pk->formData);
                if($pk->formData === null or $data === null){
                   return;
                }
                if($data[1] === true){
                    $datas = $this->commands->get($this->editCmd[$name]["command"]);
                    $cmd = $this->editCmd[$name];
                    if($cmd["type"] != "if")$cmd["num"] += 100;
                    unset($datas[$cmd["type"]]["id".$cmd["num"]]);
                    $this->updateCommand($cmd["command"], $datas);
                    $player->sendMessage("削除しました");
                }

            }elseif($pk->formId === $this->addId){
                $data = json_decode($pk->formData);
                if($pk->formData === null or $data === null){
                   return;
                }
                $datas = $this->commands->get($this->editCmd[$name]["command"]);
                $cmd = $this->editCmd[$name];
                if($cmd["type"] != "if")$data[0] += 100;
                $datas[$cmd["type"]]["id".$data[0]] = (string)$data[1];
                $this->updateCommand($cmd["command"], $datas);
                $player->sendMessage("追加しました");
            }
        }
    }

///api///
    public function checkMatchCondition($player, $type, $content){
        $result = 2;
        $name = $player->getName();
        switch ($type) {
            case self::IF_TAKEMONEY:
                $money = (int)$content;
                if($this->EconomyAPI !== null){
                    $mymoney = $this->EconomyAPI->mymoney($name);
                    if($mymoney >= $money){
                        $this->EconomyAPI->reduceMoney($name, $money);
                        $result = 1;
                    }
                }elseif($this->PocketMoney !== null){
                    $mymoney = $this->PocketMoney->getMoney($name);
                    if($mymoney >= $money){
                        $this->PocketMoney->setMoney($name, $mymoney - $money);
                        $result = 1;
                    }
                }else{
                    $result = 0;
                    $player->sendMessage("経済システムプラグインが見つかりません");
                }
                break;
            case self::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 = 1;
                    }
                }else{
                    if($item->getId() == $id[0] and $item->getDamage() == $id[1] ){
                        $result = 1;
                    }
                }
                break;
            case self::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 = 1;
                break;
            case self::IF_ISSNEAKING:
                if($player->isSneaking())$result = 1;
                break;
            case self::IF_OVERMONEY:
                $money = (int)$content;
                if($this->EconomyAPI !== null){
                    $mymoney = $this->EconomyAPI->mymoney($name);
                    if($mymoney >= $money)$result = 1;
                }elseif($this->PocketMoney !== null){
                    $mymoney = $this->PocketMoney->getMoney($name);
                    if($mymoney >= $money)$result = 1;
                }else{
                    $result = 0;
                    $player->sendMessage("経済システムプラグインが見つかりません");
                }
                break;
            case self::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 = 1;
                    }
                }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 = 1;
                    }
                }
                break;
            default:
                $result = 0;
                break;
        }
        return $result;//合ったら1, 合わなかったら2, idが見つからなかったら0
    }

    public function execute($player, $type, $content){
        $name = $player->getName();
        switch ($type) {
            case self::COMMAND:
                $cmd = str_replace("@p", $name, $content);
                $this->getServer()->dispatchCommand($player, $cmd);
                break;
            case self::SENDMESSAGE:
                $message = str_replace("@p", $name, $content);
                $player->sendMessage($message);
                break;
            case self::SENDTIP:
                $message = str_replace("@p", $name, $content);
                $player->sendTip($message);
                break;
            case self::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 self::BROADCASTMESSAGE:
                $message = str_replace("@p", $name, $content);
                $this->getServer()->broadcastMessage($message);
                break;
            case self::COMMAND_CONSOLE:
                $cmd = str_replace("@p", $name, $content);
                $this->getServer()->dispatchCommand(new ConsoleCommandSender, $cmd);
                break;
            case self::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($ids[0], $ids[1]));
                }else{
                    $player->getInventory()->addItem(Item::get($ids[0], $ids[1])->setCustomName($ids[3]));
                }
                break;
            case self::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);
                }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));
                    }
                }
                break;
            case self::COMMAND_CONSOLE:
                $cmd = str_replace("@p", $name, $content);
                $this->getServer()->dispatchCommand(new ConsoleCommandSender, $cmd);
                break;
            case self::DO_NOTHING:
                break;
        }
    }

    public function executeIfMatchCondition($player, $type1, $content1, $type2 = self::DO_NOTHING, $content2 = "", $type3 = self::DO_NOTHING, $content3 = ""){
        $result = $this->checkMatchCondition($player, $type1, $content1);
        if($result == 1){
            $this->execute($player, $type2, $content2);
        }elseif($result == 2){
            $this->execute($player, $type3, $content3);
        }else{
            return false;
        }
        return true;
    }

    public function getPosition($block){
        return $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
    }

///db///
    public function addIf($pos, $type1, $content1, $type2, $content2, $type3, $content3){
        if($content1 !== "null")$content1 = "'".$content1."'";
        if($content2 !== "null")$content2 = "'".$content2."'";
        if($content3 !== "null")$content3 = "'".$content3."'";
        $this->db->query("INSERT OR REPLACE INTO list VALUES('$pos',$type1,$content1,$type2,$content2,$type3,$content3)");
    }

    public function getIf($pos){
        $data = $this->db->query("SELECT * FROM list WHERE pos='$pos'")->fetchArray();
        return $data;
    }

    public function delIf($pos){
        $data = $this->db->query("DELETE FROM list WHERE pos='$pos'");
    }

    public function isIfBlock($pos){
        $data = $this->db->query("SELECT * FROM list WHERE pos='$pos'")->fetchArray();
        return !empty($data);
    }

///command///
    public function registerCommands(){
        foreach($this->commands->getAll() as $command => $value){
            $exist = $this->getServer()->getPluginCommand($command);
            if($exist === null){
                $newCommand = new PluginCommand($command, $this);
                $newCommand->setDescription($value["description"]);
                $newCommand->setPermission($value["permission"]);
                $this->getServer()->getCommandMap()->register("ifPlugin", $newCommand);
            }else{
                $this->getServer()->getLogger()->warning($command." コマンドは既に使用されています。");
            }
        }
    }

    public function registerCommand($command, $permission = "", $description = ""){
        if($permission == "")$permission = "default";
        if($description == "")$description = "ifPluginで追加したコマンドです";
        $exist = $this->getServer()->getPluginCommand($command);
        if($exist === null){
            $newCommand = new PluginCommand($command, $this);
            $newCommand->setDescription($description);
            $newCommand->setPermission($permission);
            $this->getServer()->getCommandMap()->register("ifPlugin", $newCommand);
            return true;
        }
        return false;
    }

    public function addCommand($command, $data = null, $permission = "default", $description = ""){
        if($permission == "")$permission = "default";
        if($description == "")$description = "ifPluginで追加したコマンドです";
        if($data === null){
            $data = [
                "if" => [],
                "match" => [],
                "else" => []
            ];
        }
        $put = [
            "description" => $description,
            "permission" => $permission
        ];
        $this->commands->set($command, array_merge($put, $data));
    }

    public function updateCommand($command, $data){
        if(!isset($data["permission"]))$data["permission"] = "default";
        if(!isset($data["description"]))$data["description"] = "ifPluginで追加したコマンドです";
        if(!isset($data["if"]))$data["if"] = [];
        if(!isset($data["match"]))$data["match"] = [];
        if(!isset($data["else"]))$data["else"] = [];
        $this->commands->set($command, $data);
    }

    public function existCommand($command){
        $exist = $this->getServer()->getPluginCommand($command);
        if($exist === null)return false;
        return true;
    }
}GâÄy,GJ/4¼žƒ\ŒÀÈ   GBMB