Added PluginBase::getCommand()

This commit is contained in:
Shoghi Cervantes 2014-03-27 14:56:02 +01:00
parent 605231251a
commit 2385b94ba3
41 changed files with 27 additions and 4 deletions

View File

@ -28,6 +28,7 @@ namespace PocketMine;
use PocketMine\Block\Block;
use PocketMine\Command\CommandSender;
use PocketMine\Command\ConsoleCommandSender;
use PocketMine\Command\PluginCommand;
use PocketMine\Command\SimpleCommandMap;
use PocketMine\Entity\Entity;
use PocketMine\Event\Event;
@ -373,6 +374,19 @@ class Server{
$this->properties->set($variable, $value == true ? "1" : "0");
}
/**
* @param string $name
*
* @return PluginCommand
*/
public function getPluginCommand($name){
if(($command = $this->commandMap->getCommand($name)) instanceof PluginCommand){
return $command;
}else{
return null;
}
}
/**
* @return Server
*/

View File

@ -24,6 +24,7 @@ namespace PocketMine\Plugin;
use PocketMine\Command\Command;
use PocketMine\Command\CommandExecutor;
use PocketMine\Command\CommandSender;
use PocketMine\Command\PluginCommand;
use PocketMine\Server;
use PocketMine\Utils\Config;
@ -125,15 +126,23 @@ abstract class PluginBase implements Plugin, CommandExecutor{
return false;
}
/* TODO
public function getCommand($name){
$this->get
}*/
$command = $this->getServer()->getPluginCommand($name);
if($command === null or $command->getPlugin() !== $this){
$command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name);
}
if($command instanceof PluginCommand and $command->getPlugin() === $this){
return $command;
}else{
return null;
}
}
/**
* @return bool
*/
public function isPhar(){
protected function isPhar(){
return $this->description instanceof \PharFileInfo;
}