I'm trying to override spawn command, by unregistering it and then registering it again, its giving an error... Error: Code: CRITICAL> TypeError: "Argument 2 passed to pocketmine\command\SimpleCommandMap::register() must be an instance of pocketmine\command\Command, instance of BruhLol\SpawnCommand given, called in F:\PocketMine-MP\plugins\Override-master\src\BruhLol\Main.php on line 145" (EXCEPTION) in "/src/pocketmine/command/SimpleCommandMap" at line 173 Code: onEnable() PHP: $cmd = "spawn";$this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__');$this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap());$this->getServer()->getCommandMap()->register("spawn", new SpawnCommand($this)); SpawnCommand.php: PHP: class SpawnCommand{ public $plugin; public function __construct(Main $plugin) { $this->plugin = $plugin; } public function execute(CommandSender $sender, Command $cmd, $alias, array $args){ if($sender instanceof Player){ if(strtolower($cmd->getName()) == "spawn"){ //override the command } } return true; }}
Clearly, SpawnCommand needs to extend pocketmine\command\Command so it can be an instance of Command.
Don't check the command name...since you've already defined that by registering it to the command map. Also, as you can see, there's no $cmd variable and there doesn't need to be.
Also there's no /spawn command in pocketmine, so its not overiding anything - unless you've got a plugin that registers the command and you're overriding that?
It can extend either, PluginCommand just adds the getPlugin(), getExecutor() and setExecutor() methods and basic checks
It can also extend implement PluginIdentifiableCommand, but PluginCommand extends Command. As long as it extends Command somewhere, it doesn't matter too much.
Yes I know that, I was just asking because that were things I believe to have read in the poggit rules
An interface can't extend a class. A plugin should always both extend Command and implement PluginIdentifableCommand. PluginCommand is usually not appropriate for overriding, because it is just a class for instantiating commands defined in plugin.yml
It might not be good for overriding, but it does extend Command and implement PluginIdentifiableCommand
PluginIdentifiableCommand just includes a getPlugin function and is not necessary for making commands, one can make a custom command class by extending Command or extending PluginCommand(which just extends Command and implements PluginIdentifiableCommand.) I personally choose to extend Command and make an abstract BaseCommand class.