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

Solved construct error

Discussion in 'Development' started by UnknownOre, Feb 9, 2019.

  1. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    Main.php
    PHP:
    $this->getServer()->getCommandMap()->register("enchantui", new ShopCommand($this));
    ShopCommand.php
    PHP:
    public function __construct(Main $plugin) {
            
    parent::__construct($plugin'enchantui''Main Enchant command', ['eshop''es']);
        }
    i keep getting the following error:
    Code:
    TypeError: "Argument 1 passed to pocketmine\command\Command::__construct() must be of the type string, object given, called in /home/minecraft/plugins/EnchantUI/src/UnknownOre/ShopCommand.php on line 10" (EXCEPTION) in "src/pocketmine/command/Command" at line 81
    
    i dont Know what's wrong
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    parent::__construct(); must be compatioble with parent class's __construct method
    PHP:
    /**
    * PluginCommand constructor.
    * @param string $name
    * @param Plugin $owner
    */
    public function __construct(string $namePlugin $owner);
    so you must add description using other functions

    PHP:
    public function __construct(Main $plugin) {
            
    parent::__construct('enchantui'$plugin);
            
    $this->setAliases(['eshop','es']);
            
    $this->setDescription('Main Enchant command');
     }
     
    UnknownOre likes this.
  3. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    i got this error after doing what you have said
    Code:
    TypeError: "Argument 2 passed to pocketmine\command\Command::__construct() must be of the type string, object given, called in /home/minecraft/plugins/EnchantUI/src/UnknownOre/ShopCommand.php on line 10" (EXCEPTION) in "src/pocketmine/command/Command" at line 81
    
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    how seems line 10?
     
  5. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    PHP:
    parent::__construct('enchantui'$plugin);
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    and the line where starting class
    eg
    PHP:
    class Enchantuicommand extends PluginCommand
     
    UnknownOre likes this.
  7. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    Thank You! it worked
     
  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.