mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-17 17:04:08 +00:00
Added correct PluginIdentifiableCommand
This commit is contained in:
parent
27fcf0286e
commit
04917ecd5a
@ -32,6 +32,7 @@ use pocketmine\command\CommandReader;
|
|||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\ConsoleCommandSender;
|
use pocketmine\command\ConsoleCommandSender;
|
||||||
use pocketmine\command\PluginCommand;
|
use pocketmine\command\PluginCommand;
|
||||||
|
use pocketmine\command\PluginIdentifiableCommand;
|
||||||
use pocketmine\command\SimpleCommandMap;
|
use pocketmine\command\SimpleCommandMap;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\HandlerList;
|
use pocketmine\event\HandlerList;
|
||||||
@ -1014,10 +1015,10 @@ class Server{
|
|||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return PluginCommand
|
* @return PluginIdentifiableCommand
|
||||||
*/
|
*/
|
||||||
public function getPluginCommand($name){
|
public function getPluginCommand($name){
|
||||||
if(($command = $this->commandMap->getCommand($name)) instanceof PluginCommand){
|
if(($command = $this->commandMap->getCommand($name)) instanceof PluginIdentifiableCommand){
|
||||||
return $command;
|
return $command;
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return null;
|
||||||
|
@ -24,7 +24,7 @@ namespace pocketmine\command;
|
|||||||
use pocketmine\plugin\Plugin;
|
use pocketmine\plugin\Plugin;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
class PluginCommand extends Command{
|
class PluginCommand extends Command implements PluginIdentifiableCommand{
|
||||||
|
|
||||||
/** @var Plugin */
|
/** @var Plugin */
|
||||||
private $owningPlugin;
|
private $owningPlugin;
|
||||||
@ -39,7 +39,11 @@ class PluginCommand extends Command{
|
|||||||
public function __construct($name, Plugin $owner){
|
public function __construct($name, Plugin $owner){
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
$this->owningPlugin = $owner;
|
$this->owningPlugin = $owner;
|
||||||
|
if(!($owner instanceof CommandExecutor)){
|
||||||
|
trigger_error("Plugin does not implement CommandExecutor", E_USER_WARNING);
|
||||||
|
}else{
|
||||||
$this->executor = $owner;
|
$this->executor = $owner;
|
||||||
|
}
|
||||||
$this->usageMessage = "";
|
$this->usageMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
src/pocketmine/command/PluginIdentifiableCommand.php
Normal file
30
src/pocketmine/command/PluginIdentifiableCommand.php
Normal 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();
|
||||||
|
}
|
@ -25,6 +25,7 @@ use pocketmine\command\Command;
|
|||||||
use pocketmine\command\CommandExecutor;
|
use pocketmine\command\CommandExecutor;
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\PluginCommand;
|
use pocketmine\command\PluginCommand;
|
||||||
|
use pocketmine\command\PluginIdentifiableCommand;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{
|
|||||||
$command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name);
|
$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;
|
return $command;
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return null;
|
||||||
|
@ -151,6 +151,11 @@ class PluginManager{
|
|||||||
if(($plugin = $loader->loadPlugin($path)) instanceof Plugin){
|
if(($plugin = $loader->loadPlugin($path)) instanceof Plugin){
|
||||||
$this->plugins[$plugin->getDescription()->getName()] = $plugin;
|
$this->plugins[$plugin->getDescription()->getName()] = $plugin;
|
||||||
|
|
||||||
|
$pluginCommands = $this->parseYamlCommands($plugin);
|
||||||
|
|
||||||
|
if(count($pluginCommands) > 0){
|
||||||
|
$this->commandMap->registerAll($plugin->getDescription()->getName(), $pluginCommands);
|
||||||
|
}
|
||||||
return $plugin;
|
return $plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,11 +505,6 @@ class PluginManager{
|
|||||||
*/
|
*/
|
||||||
public function enablePlugin(Plugin $plugin){
|
public function enablePlugin(Plugin $plugin){
|
||||||
if(!$plugin->isEnabled()){
|
if(!$plugin->isEnabled()){
|
||||||
$pluginCommands = $this->parseYamlCommands($plugin);
|
|
||||||
|
|
||||||
if(count($pluginCommands) > 0){
|
|
||||||
$this->commandMap->registerAll($plugin->getDescription()->getName(), $pluginCommands);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($plugin->getDescription()->getPermissions() as $perm){
|
foreach($plugin->getDescription()->getPermissions() as $perm){
|
||||||
$this->addPermission($perm);
|
$this->addPermission($perm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user