Added correct PluginIdentifiableCommand

This commit is contained in:
Shoghi Cervantes 2014-04-03 13:08:11 +02:00
parent 27fcf0286e
commit 04917ecd5a
5 changed files with 46 additions and 10 deletions

View File

@ -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;

View File

@ -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 = "";
}

View File

@ -0,0 +1,30 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command;
interface PluginIdentifiableCommand{
/**
* @return \pocketmine\plugin\plugin
*/
public function getPlugin();
}

View File

@ -25,6 +25,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;
use pocketmine\command\PluginIdentifiableCommand;
use pocketmine\Server;
use pocketmine\utils\Config;
@ -137,7 +138,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{
$command = $this->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;

View File

@ -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);