1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved SimpleCommandMap::register() Error

Discussion in 'Development' started by BruhLol, May 18, 2017.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    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 $senderCommand $cmd$alias, array $args){
            if(
    $sender instanceof Player){
                if(
    strtolower($cmd->getName()) == "spawn"){
                 
    //override the command
                
    }
            }
        return 
    true;
     }
    }
     
    Last edited: May 18, 2017
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Clearly, SpawnCommand needs to extend pocketmine\command\Command so it can be an instance of Command.
     
    BruhLol likes this.
  3. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    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.
     
    BruhLol likes this.
  4. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    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?
     
  5. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Shouldn't plugins always extend PluginCommand?
     
    jasonwynn10 likes this.
  6. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    It can extend either, PluginCommand just adds the getPlugin(), getExecutor() and setExecutor() methods and basic checks
     
    jasonwynn10 and corytortoise like this.
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    It can also extend implement PluginIdentifiableCommand, but PluginCommand extends Command. As long as it extends Command somewhere, it doesn't matter too much.
     
    Last edited: May 19, 2017
  8. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Yes I know that, I was just asking because that were things I believe to have read in the poggit rules
     
  9. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    PluginIdentifiableCommand is an interface
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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
     
    jasonwynn10 and BruhLol like this.
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Oops, thanks for pointing it out, I should have checked before I posted.
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    It might not be good for overriding, but it does extend Command and implement PluginIdentifiableCommand
     
    SOFe likes this.
  13. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    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.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.