mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 11:27:07 +00:00
Remove PluginIdentifiableCommand in favour of a more generic PluginOwned interface
This commit is contained in:
parent
6b037d6a4c
commit
3238b4ff33
@ -27,10 +27,10 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace pocketmine;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandReader;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\ConsoleCommandSender;
|
||||
use pocketmine\command\PluginIdentifiableCommand;
|
||||
use pocketmine\command\SimpleCommandMap;
|
||||
use pocketmine\crafting\CraftingManager;
|
||||
use pocketmine\crafting\CraftingManagerFromDataHelper;
|
||||
@ -71,6 +71,7 @@ use pocketmine\plugin\Plugin;
|
||||
use pocketmine\plugin\PluginGraylist;
|
||||
use pocketmine\plugin\PluginLoadOrder;
|
||||
use pocketmine\plugin\PluginManager;
|
||||
use pocketmine\plugin\PluginOwned;
|
||||
use pocketmine\plugin\ScriptPluginLoader;
|
||||
use pocketmine\resourcepacks\ResourcePackManager;
|
||||
use pocketmine\scheduler\AsyncPool;
|
||||
@ -694,10 +695,11 @@ class Server{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PluginIdentifiableCommand|null
|
||||
* @return Command|PluginOwned|null
|
||||
* @phpstan-return (Command&PluginOwned)|null
|
||||
*/
|
||||
public function getPluginCommand(string $name){
|
||||
if(($command = $this->commandMap->getCommand($name)) instanceof PluginIdentifiableCommand){
|
||||
if(($command = $this->commandMap->getCommand($name)) instanceof PluginOwned){
|
||||
return $command;
|
||||
}else{
|
||||
return null;
|
||||
|
@ -25,11 +25,11 @@ namespace pocketmine\command;
|
||||
|
||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\plugin\PluginOwned;
|
||||
use pocketmine\plugin\PluginOwnedTrait;
|
||||
|
||||
class PluginCommand extends Command implements PluginIdentifiableCommand{
|
||||
|
||||
/** @var Plugin */
|
||||
private $owningPlugin;
|
||||
class PluginCommand extends Command implements PluginOwned{
|
||||
use PluginOwnedTrait;
|
||||
|
||||
/** @var CommandExecutor */
|
||||
private $executor;
|
||||
@ -67,8 +67,4 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
|
||||
public function setExecutor(CommandExecutor $executor) : void{
|
||||
$this->executor = $executor;
|
||||
}
|
||||
|
||||
public function getPlugin() : Plugin{
|
||||
return $this->owningPlugin;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandExecutor;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\PluginCommand;
|
||||
use pocketmine\command\PluginIdentifiableCommand;
|
||||
use pocketmine\scheduler\TaskScheduler;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
@ -223,15 +222,16 @@ abstract class PluginBase implements Plugin, CommandExecutor{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Command|PluginIdentifiableCommand|null
|
||||
* @return Command|PluginOwned|null
|
||||
* @phpstan-return (Command&PluginOwned)|null
|
||||
*/
|
||||
public function getCommand(string $name){
|
||||
$command = $this->getServer()->getPluginCommand($name);
|
||||
if($command === null or $command->getPlugin() !== $this){
|
||||
if($command === null or $command->getOwningPlugin() !== $this){
|
||||
$command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name);
|
||||
}
|
||||
|
||||
if($command instanceof PluginIdentifiableCommand and $command->getPlugin() === $this){
|
||||
if($command instanceof PluginOwned and $command->getOwningPlugin() === $this){
|
||||
return $command;
|
||||
}else{
|
||||
return null;
|
||||
|
@ -21,11 +21,12 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\command;
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
use pocketmine\plugin\Plugin;
|
||||
/**
|
||||
* This interface may be implemented by objects which are owned by plugins, to allow them to be identified as such.
|
||||
*/
|
||||
interface PluginOwned{
|
||||
|
||||
interface PluginIdentifiableCommand{
|
||||
|
||||
public function getPlugin() : Plugin;
|
||||
public function getOwningPlugin() : Plugin;
|
||||
}
|
40
src/plugin/PluginOwnedTrait.php
Normal file
40
src/plugin/PluginOwnedTrait.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
/**
|
||||
* @see PluginOwned
|
||||
*/
|
||||
trait PluginOwnedTrait{
|
||||
/** @var Plugin */
|
||||
private $owningPlugin;
|
||||
|
||||
public function __construct(Plugin $owningPlugin){
|
||||
$this->owningPlugin = $owningPlugin;
|
||||
}
|
||||
|
||||
public function getOwningPlugin() : Plugin{
|
||||
return $this->owningPlugin;
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit beb079c256eea7cae0f68f02e2b61096ddc00690
|
||||
Subproject commit aef2b101855762bf02638dfdb64bec585f5cba68
|
Loading…
x
Reference in New Issue
Block a user