<?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