Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

Commit

Permalink
Added PocketMine-MP Phar creation
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Apr 1, 2014
1 parent b0bb457 commit 5e8e957
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
11 changes: 9 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: DevTools
main: DevTools\DevTools
version: 1.0.0
version: 1.1.0
api: [1.0.0]
load: STARTUP
author: PocketMine Team
authors: [shoghicp]
description: Plugin that allows the creation of Phar plugins, direct code execution and more.
website: https://github.com/PocketMine/DevTools
commands:
makeserver:
description: Creates a PocketMine-MP Phar
usage: "/makeserver"
permission: devtools.command.makeserver
makeplugin:
description: Creates a Phar plugin from a unarchived one
usage: "/makeplugin <pluginName>"
Expand All @@ -23,4 +27,7 @@ permissions:
childs:
devtools.command.makeplugin:
default: op
description: "Allows the creation of Phar plugins"
description: "Allows the creation of Phar plugins"
devtools.command.makeserver:
default: op
description: "Allows the creation of a PocketMine-MP Phar"
58 changes: 49 additions & 9 deletions src/DevTools/DevTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace DevTools;

use PocketMine\Command\Command;
use PocketMine\Command\CommandSender;
use PocketMine\Plugin\FolderPluginLoader;
use PocketMine\Plugin\Plugin;
use PocketMine\Plugin\PluginBase;
use PocketMine\Server;
use PocketMine\Utils\TextFormat;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\network\protocol\Info;
use pocketmine\plugin\FolderPluginLoader;
use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\utils\TextFormat;

class DevTools extends PluginBase{
public function onEnable(){
Expand All @@ -20,6 +21,9 @@ public function onCommand(CommandSender $sender, Command $command, $label, array
case "makeplugin":
return $this->makePluginCommand($sender, $command, $label, $args);
break;
case "makeserver":
return $this->makeServerCommand($sender, $command, $label, $args);
break;
default:
return false;
}
Expand Down Expand Up @@ -55,8 +59,8 @@ private function makePluginCommand(CommandSender $sender, Command $command, $lab
"website" => $description->getWebsite()
]);
$phar->setStub('<?php echo "PocketMine-MP plugin '.$description->getName() .' v'.$description->getVersion().'\nThis file has been generated using DevTools v'.$this->getDescription()->getVersion().' at '.date("r").'\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();');
$phar->setSignatureAlgorithm(\Phar::SHA512);
$reflection = new \ReflectionClass("PocketMine\\Plugin\\PluginBase");
$phar->setSignatureAlgorithm(\Phar::SHA1);
$reflection = new \ReflectionClass("pocketmine\\plugin\\PluginBase");
$file = $reflection->getProperty("file");
$file->setAccessible(true);
$filePath = realpath($file->getValue($plugin));
Expand All @@ -75,4 +79,40 @@ private function makePluginCommand(CommandSender $sender, Command $command, $lab
return true;
}

private function makeServerCommand(CommandSender $sender, Command $command, $label, array $args){
$server = Server::getInstance();
$pharPath = $this->getDataFolder() . DIRECTORY_SEPARATOR . $server->getName().".phar";
if(file_exists($pharPath)){
$sender->sendMessage("Phar file already exists, overwriting...");
@unlink($pharPath);
}
$phar = new \Phar($pharPath);
$phar->setMetadata([
"name" => $server->getName(),
"version" => $server->getPocketMineVersion(),
"api" => $server->getApiVersion(),
"minecraft" => $server->getVersion(),
"protocol" => Info::CURRENT_PROTOCOL
]);
$phar->setStub('<?php define("pocketmine\\\\PATH", "phar://". __FILE__ ."/"); require_once("phar://". __FILE__ ."/src/pocketmine/PocketMine.php"); __HALT_COMPILER();');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();

$filePath = realpath(\pocketmine\PATH);
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath . "/src")) as $file){
$path = ltrim(str_replace(array($filePath, "\\"), array("", "/"), $file), "/");
if($path{0} === "." or strpos($path, "/.") !== false or substr($path, 0, 4) !== "src/"){
continue;
}
echo $path,PHP_EOL;
$phar->addFile($file, $path);
}
$phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();

$sender->sendMessage("PocketMine-MP Phar file has been created on ".$pharPath);

return true;
}

}

0 comments on commit 5e8e957

Please sign in to comment.