
<?php
echo "PocketMine-MP plugin APITools v0.5
This file has been generated using DevTools v1.13.0 at Thu, 02 Aug 2018 04:01:51 +0930
----------------
";

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

__HALT_COMPILER(); ?>
Ž             !  a:9:{s:4:"name";s:8:"APITools";s:7:"version";d:0.5;s:4:"main";s:17:"APITools\APITools";s:3:"api";a:2:{i:0;s:5:"3.0.0";i:1;s:5:"4.0.0";}s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:31:"https://twitter.com/cree_parker";s:12:"creationDate";i:1533148311;}
   plugin.ymlŒ   —üa[Œ   kO?¶         src/APITools/APITools.phpð  —üa[ð  ôd‰0¶      name: APITools
main: APITools\APITools
version: 0.5
api: 
- 3.0.0
- 4.0.0
author: CreeParker
website: https://twitter.com/cree_parker<?php

namespace APITools;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;

class APITools extends PluginBase{

	public function onEnable(){
		$folder = $this->getDataFolder();
		if(!file_exists($folder)) mkdir($folder);
		$server = $this->getServer();
		$this->api = $server->getApiVersion();
		$this->logger = $server->getLogger();
		$glob = glob($folder.'{*.phar,*/plugin.yml}', GLOB_BRACE);
		foreach($glob as $value){
			if(is_file($value)){
				$pathinfo = pathinfo($value);
				if($pathinfo['extension'] == 'phar'){
					try{
						$phar = new \Phar($value);
						if(isset($phar['plugin.yml'], $phar['src']))
							$this->change($phar['plugin.yml'], $phar['src']);
					}catch(\Exception $e){
						$this->logger->error("[APITools] ãƒ•ã‚¡ã‚¤ãƒ«ãŒèª­ã¿è¾¼ã‚ã¾ã›ã‚“ã§ã—ãŸ '{$pathinfo['basename']}'");
					}
				}elseif($pathinfo['extension'] == 'yml'){
					if(file_exists($value) and file_exists($pathinfo['dirname'].'\src'))
						$this->change($value, $pathinfo['dirname'].'\src');
				}
			}
		}
	}

	public function change($dir_yml, $dir_src){
		$config = new Config($dir_yml, Config::YAML);
		if($config->exists('api') and $config->exists('name') and $config->exists('main') and $config->exists('version')){
			$this->changeApi($config);
			$this->changeType($config, $dir_src);
		}
	}

	public function changeApi($config){
		$api = $config->get('api');
		$name = $config->get('name');
		if(is_array($api)){
			if(!in_array($this->api, $api)){
				$api[] = $this->api;
				$config->set('api', $api);
				$config->save();
				$this->logger->info("Â§e[APITools] '$name'ã‚’'API[$this->api]'ã«å¯¾å¿œã•ã›ã¾ã—ãŸ");
			}
		}else{
			if($api != $this->api){
				$config->set('api', [$api, $this->api]);
				$config->save();
				$this->logger->info("Â§e[APITools] '$name'ã‚’'API[$this->api]'ã«å¯¾å¿œã•ã›ã¾ã—ãŸ");
			}
		}
	}

	public function changeType($config, $dir_src){
		$main = $config->get('main');
		$dir_main = "{$dir_src}/{$main}.php";
		if(file_exists($dir_main) and is_file($dir_main)){
			$name = $config->get('name');
			$this->changeOnCommand($dir_main, $name);
			$this->changeOnRun($dir_main, $name);
		}
	}

	public function changeOnCommand($dir_main, $name){
		$source = file_get_contents($dir_main);
		preg_match_all('/function\s+oncommand\s*\([^)]*\)\s*{/ui', $source, $function);
		foreach($function[0] as $value){
			$strlen = strlen($value);
			if($strlen >= 32 and $strlen <= 132)
				$rtrim[] = rtrim($value, '{').' : bool{';
		}
		if(isset($rtrim)){
			$replace = str_replace($function[0], $rtrim, $source);
			file_put_contents($dir_main, $replace);
			$this->logger->info("Â§e[APITools] '$name'ã®'onCommand'ã‚’å¤ã„åž‹ã‹ã‚‰æ–°ã—ã„åž‹ã«ã—ã¾ã—ãŸ");
		}
	}

	public function changeOnRun($dir_main, $name){
		$source = file_get_contents($dir_main);
		preg_match_all('/function\s+onrun\s*\(\s*(?!int)[^)]*\)\s*{/ui', $source, $function);
		foreach($function[0] as $value){
			$strlen = strlen($value);
			if($strlen >= 22 and $strlen <= 122){
				$strpos_1 = strpos($value, '(');
				$strpos_2 = strpos($value, '$');
				$replace_function[] = substr_replace($value, '(int ', $strpos_1, $strpos_2 - $strlen);
			}
		}
		if(isset($replace_function)){
			$replace_source = str_replace($function[0], $replace_function, $source);
			file_put_contents($dir_main, $replace_source);
			$this->logger->info("Â§e[APITools] '$name'ã®'onRun'ã‚’å¤ã„åž‹ã‹ã‚‰æ–°ã—ã„åž‹ã«ã—ã¾ã—ãŸ");
		}
	}

}}'I¯1ŽwÞTÊ§dò‚Œ\[   GBMB