Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command: /makeplugin * #19

Merged
merged 7 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
- Restart the server. The plugin will be loaded

## Usage
* _/makeplugin <pluginName>_: Creates a Phar plugin archive for its distribution
* _/makeplugin \<pluginName\>_: Creates a Phar plugin archive for its distribution
* _/makeplugin *_: Creates Phar plugin archives for all loaded plugins
* _/makeserver_: Creates a PocketMine-MP Phar archive
* _/checkperm <node> [playerName]_: Checks a permission node
* _/checkperm \<node\> [playerName]_: Checks a permission node

## Using ConsoleScript to build a DevTools phar from source code
Contrary to popular assumption, this is very simple. Assuming you have a php executable in your PATH variable, cd into the DevTools directory (the folder where plugin.yml is located) and simply run the following:
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: DevTools
main: DevTools\DevTools
version: 1.12.4
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8]
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has an ALPHA9 requirement? It can be pushed to ALPHA8 without any problems

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how your bump commit snuck in there...

load: STARTUP
author: PocketMine Team
description: Helps develop and distribute PocketMine-MP plugins
Expand Down
23 changes: 21 additions & 2 deletions src/DevTools/DevTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public function onCommand(CommandSender $sender, Command $command, string $label
case "makeplugin":
if(isset($args[0]) and $args[0] === "FolderPluginLoader"){
return $this->makePluginLoader($sender, $command, $label, $args);
}elseif(isset($args[0]) and $args[0] === "*"){
$plugins = $this->getServer()->getPluginManager()->getPlugins();
$succeeded = $failed = [];
foreach($plugins as $plugin){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should check if the loader is a FolderPluginLoader instance before trying to build it.

makeplugin *
[10:09:58] [Server thread/INFO]: Plugin DevTools is not in folder structure.
[10:09:58] [Server thread/INFO]: [DevTools] Adding files...
[10:09:58] [Server thread/INFO]: [DevTools] Added 4 files
[10:09:58] [Server thread/INFO]: [DevTools] Checking for compressible files...
[10:09:58] [Server thread/INFO]: [DevTools] Done in 0.427s
[10:09:58] [Server thread/INFO]: Phar plugin DumpBadLogins v0.0.1 has been created on plugins\DevTools/\DumpBadLogins_v0.0.1.phar
[10:09:58] [Server thread/INFO]: [DevTools] Adding files...
[10:09:58] [Server thread/INFO]: [DevTools] Added 2 files
[10:09:58] [Server thread/INFO]: [DevTools] Checking for compressible files...
[10:09:58] [Server thread/INFO]: [DevTools] Done in 0.041s
[10:09:58] [Server thread/INFO]: Phar plugin FloatingText v0.0.1 has been created on plugins\DevTools/\FloatingText_v0.0.1.phar
[10:09:58] [Server thread/INFO]: [DevTools] Adding files...
[10:09:58] [Server thread/INFO]: [DevTools] Added 2 files
[10:09:58] [Server thread/INFO]: [DevTools] Checking for compressible files...
[10:09:58] [Server thread/INFO]: [DevTools] Done in 0.054s
[10:09:58] [Server thread/INFO]: Phar plugin test v0.0.1 has been created on plugins\DevTools/\test_v0.0.1.phar
[10:09:58] [Server thread/INFO]: 1 plugin failed to build: DevTools
[10:09:58] [Server thread/INFO]: 3/4 plugins successfully built: DumpBadLogins, FloatingText, test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since makeplugin doesn't check either I left it as it was - I was more concerned about whether to exclude DevTools itself, or leave it for informational purposes.

Edit - I mean that this is checked within makePluginCommand(), so I didn't also add a check for within onCommand(). I've added the check in the latest commit, but this simply silences the error "Plugin DevTools is not in folder structure."

if($this->makePluginCommand($sender, $command, $label, [$plugin->getName()])){
$succeeded[] = $plugin->getName();
}else{
$failed[] = $plugin->getName();
}
}
if(count($failed) > 0){
$sender->sendMessage(TextFormat::RED . count($failed) . " plugin"
. (count($failed) === 1 ? "" : "s") . " failed to build: " . implode(", ", $failed));
}
if(count($succeeded) > 0){
$sender->sendMessage(TextFormat::GREEN . count($succeeded) . "/" . count($plugins) . " plugin"
. (count($plugins) === 1 ? "" : "s") . " successfully built: " . implode(", ", $succeeded));
}
return true;
}else{
return $this->makePluginCommand($sender, $command, $label, $args);
}
Expand Down Expand Up @@ -146,13 +165,13 @@ private function makePluginCommand(CommandSender $sender, Command $command, stri
$pluginName = trim(implode(" ", $args));
if($pluginName === "" or !(($plugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName)) instanceof Plugin)){
$sender->sendMessage(TextFormat::RED . "Invalid plugin name, check the name case.");
return true;
return false;
}
$description = $plugin->getDescription();

if(!($plugin->getPluginLoader() instanceof FolderPluginLoader)){
$sender->sendMessage(TextFormat::RED . "Plugin " . $description->getName() . " is not in folder structure.");
return true;
return false;
}

$pharPath = $this->getDataFolder() . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . ".phar";
Expand Down