diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 0299c0574..f62c9fb57 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -32,6 +32,7 @@ use pocketmine\command\CommandReader; use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\command\PluginCommand; +use pocketmine\command\PluginIdentifiableCommand; use pocketmine\command\SimpleCommandMap; use pocketmine\entity\Entity; use pocketmine\event\HandlerList; @@ -1014,10 +1015,10 @@ class Server{ /** * @param string $name * - * @return PluginCommand + * @return PluginIdentifiableCommand */ public function getPluginCommand($name){ - if(($command = $this->commandMap->getCommand($name)) instanceof PluginCommand){ + if(($command = $this->commandMap->getCommand($name)) instanceof PluginIdentifiableCommand){ return $command; }else{ return null; diff --git a/src/pocketmine/command/PluginCommand.php b/src/pocketmine/command/PluginCommand.php index 401926b37..f60aa7559 100644 --- a/src/pocketmine/command/PluginCommand.php +++ b/src/pocketmine/command/PluginCommand.php @@ -24,7 +24,7 @@ namespace pocketmine\command; use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; -class PluginCommand extends Command{ +class PluginCommand extends Command implements PluginIdentifiableCommand{ /** @var Plugin */ private $owningPlugin; @@ -39,7 +39,11 @@ class PluginCommand extends Command{ public function __construct($name, Plugin $owner){ parent::__construct($name); $this->owningPlugin = $owner; - $this->executor = $owner; + if(!($owner instanceof CommandExecutor)){ + trigger_error("Plugin does not implement CommandExecutor", E_USER_WARNING); + }else{ + $this->executor = $owner; + } $this->usageMessage = ""; } diff --git a/src/pocketmine/command/PluginIdentifiableCommand.php b/src/pocketmine/command/PluginIdentifiableCommand.php new file mode 100644 index 000000000..df0e7062b --- /dev/null +++ b/src/pocketmine/command/PluginIdentifiableCommand.php @@ -0,0 +1,30 @@ +getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name); } - if($command instanceof PluginCommand and $command->getPlugin() === $this){ + if($command instanceof PluginIdentifiableCommand and $command->getPlugin() === $this){ return $command; }else{ return null; diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index c948ce329..f001d24e5 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -151,6 +151,11 @@ class PluginManager{ if(($plugin = $loader->loadPlugin($path)) instanceof Plugin){ $this->plugins[$plugin->getDescription()->getName()] = $plugin; + $pluginCommands = $this->parseYamlCommands($plugin); + + if(count($pluginCommands) > 0){ + $this->commandMap->registerAll($plugin->getDescription()->getName(), $pluginCommands); + } return $plugin; } } @@ -500,11 +505,6 @@ class PluginManager{ */ public function enablePlugin(Plugin $plugin){ if(!$plugin->isEnabled()){ - $pluginCommands = $this->parseYamlCommands($plugin); - - if(count($pluginCommands) > 0){ - $this->commandMap->registerAll($plugin->getDescription()->getName(), $pluginCommands); - } foreach($plugin->getDescription()->getPermissions() as $perm){ $this->addPermission($perm);