<?php echo "PocketMine-MP plugin APITools v0.3\nThis file has been generated using DevTools v1.12.9 at Thu, 22 Mar 2018 00:47:42 +1030\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:8:"APITools";s:7:"version";s:3:"0.3";s:4:"main";s:17:"APITools\APITools";s:3:"api";a:30:{i:0;s:12:"3.0.0-ALPHA1";i:1;s:12:"3.0.0-ALPHA2";i:2;s:12:"3.0.0-ALPHA3";i:3;s:12:"3.0.0-ALPHA4";i:4;s:12:"3.0.0-ALPHA5";i:5;s:12:"3.0.0-ALPHA6";i:6;s:12:"3.0.0-ALPHA7";i:7;s:12:"3.0.0-ALPHA8";i:8;s:12:"3.0.0-ALPHA9";i:9;s:13:"3.0.0-ALPHA10";i:10;s:13:"3.0.0-ALPHA11";i:11;s:13:"3.0.0-ALPHA12";i:12;s:13:"3.0.0-ALPHA13";i:13;s:13:"3.0.0-ALPHA14";i:14;s:13:"3.0.0-ALPHA15";i:15;s:13:"3.0.0-ALPHA16";i:16;s:13:"3.0.0-ALPHA17";i:17;s:13:"3.0.0-ALPHA18";i:18;s:13:"3.0.0-ALPHA19";i:19;s:13:"3.0.0-ALPHA20";i:20;s:13:"3.0.0-ALPHA21";i:21;s:13:"3.0.0-ALPHA22";i:22;s:13:"3.0.0-ALPHA23";i:23;s:13:"3.0.0-ALPHA24";i:24;s:13:"3.0.0-ALPHA25";i:25;s:13:"3.0.0-ALPHA26";i:26;s:13:"3.0.0-ALPHA27";i:27;s:13:"3.0.0-ALPHA28";i:28;s:13:"3.0.0-ALPHA29";i:29;s:13:"3.0.0-ALPHA30";}s:6:"depend";a:0:{}s:11:"description";s:0:"";s:7:"authors";a:1:{i:0;s:10:"CreeParker";}s:7:"website";s:31:"https://twitter.com/cree_parker";s:12:"creationDate";i:1521641862;}
   plugin.yml}  †i²Z}  ©1’û¶         src/APITools/APITools.phpð  †i²Zð  RS™¶      name: APITools
main: APITools\APITools
version: 0.3
api:
- 3.0.0-ALPHA1
- 3.0.0-ALPHA2
- 3.0.0-ALPHA3
- 3.0.0-ALPHA4
- 3.0.0-ALPHA5
- 3.0.0-ALPHA6
- 3.0.0-ALPHA7
- 3.0.0-ALPHA8
- 3.0.0-ALPHA9
- 3.0.0-ALPHA10
- 3.0.0-ALPHA11
- 3.0.0-ALPHA12
- 3.0.0-ALPHA13
- 3.0.0-ALPHA14
- 3.0.0-ALPHA15
- 3.0.0-ALPHA16
- 3.0.0-ALPHA17
- 3.0.0-ALPHA18
- 3.0.0-ALPHA19
- 3.0.0-ALPHA20
- 3.0.0-ALPHA21
- 3.0.0-ALPHA22
- 3.0.0-ALPHA23
- 3.0.0-ALPHA24
- 3.0.0-ALPHA25
- 3.0.0-ALPHA26
- 3.0.0-ALPHA27
- 3.0.0-ALPHA28
- 3.0.0-ALPHA29
- 3.0.0-ALPHA30
load: STARTUP
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("Â§a[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'ã‚’å¤ã„åž‹ã‹ã‚‰æ–°ã—ã„åž‹ã«ã—ã¾ã—ãŸ");
		}
	}

}EÛXw!yY‡§Üh—ÕýŠ»?øä   GBMB