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

__construct Error

Discussion in 'Development' started by KygekDev, Aug 8, 2020.

  1. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    I've recently added __constuct so command aliases can be added and command description can be changed. But it got an error:
    Code:
    Fatal error: Declaration of Kygekraqmak\KygekRulesUI\Main::__construct($name, pocketmine\plugin\Plugin $plugin) must be compatible with pocketmine\plugin\Plugin::__construct(pocketmine\plugin\PluginLoader $loader, pocketmine\Server $server, pocketmine\plugin\PluginDescription $description, string $dataFolder, string $file) in src/Kygekraqmak/KygekRulesUI/Main.php on line 33
    [Error] -> PHPStan (255) - Unable to parse.
    I guess the error is around here, but I don't know how to fix it. This is just a part of the code.
    PHP:
    use pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\{CommandCommandSenderCommandExecutorConsoleCommandSenderPluginIdentifiableCommand};

    use 
    jojoe77777\FormAPI;
    use 
    jojoe77777\FormAPI\SimpleForm;

    class 
    Main extends PluginBase implements Listener {

      public 
    $plugin;

      public function 
    __construct($namePlugin $plugin) {
        
    $this->plugin $plugin;
        
    parent::__construct("rules");
        
    $this->setDescription($this->getConfig()->get("command-description"));
        
    $this->setPermission("rules.command");
        
    $this->setAliases($this->getConfig()->get("command-aliases"));
      }
    So what should I add/change/remove? Any help would be appreciated.

    Project: https://github.com/Kygekraqmak/KygekRulesUI
     
  2. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Use this code on Main file
    PHP:
    use Kygekraqmak\KygekRulesUI\command\RulesCMD;
    //use in function onEnable
    $this->getServer()->getCommandMap()->regsiter("rules", new RulesCMD($this));
    Create new Folder command and Create File RulesCMD Code
    PHP:
    <?php

    namespace Kygekraqmak\KygekRulesUI;

    use 
    pocketmine\command\{CommandCommandSender};

    use 
    jojoe77777\FormAPI;
    use 
    jojoe77777\FormAPI\SimpleForm;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    Kygekraqmak\KygekRulesUI\Main;

    class 
    RulesCMD extends Command{
    public function 
    __construct($nameMain $plugin) {
        
    $this->main $plugin;
         
    $config $this->main->getConfig();
        
    parent::__construct("rules");
        
    $this->setDescription($config->get("command-description"));
        
    $this->setAliases($config->get("command-aliases"));
       }
       public function 
    execute(CommandSender $pstring $currentAlias, array $agrs){
         if(
    $p instanceof Player){
        
    $this->main->kygekRulesUI($p);
       }
      }
    }
     
    Primus likes this.
  3. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    First, why $this->setPermission("rules.command"); not used?
    Second, should I move the onCommand() function in Main.php to command\RulesCMD.php?
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    1. mybe you are op?! :facepalm:

    2. learn php

    3. use public function excute(CommandSender $player,string $label, array $args) {
    :L
    }
     
  5. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    I'm not talking about OP. I'm talking about adding permission using that with the default set to true.
    I'm learning.
     
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    1. Learn php full first then come back to plugin creation.

    2. i said:
    instead onCommand
     
  7. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    You can use it if you want, the person probably just forgot to include the permission setting.

    Actually, instead of onCommand, like in PluginBase, the Command class uses a function called execute, so there is no need for onCommand: https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/command/Command.php#L91
     
  8. Primus

    Primus Zombie Pigman

    Messages:
    749
    The check is done for you, if I recall correctly.
     
  9. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Lol, nobody dont have your full code, so we cant help you.
     
  10. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    but you can register cmd and perm for cmd in plugin .yml
    and then write new class cmd or you can use cmd fucn in class Main
     
  11. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also you can write your cmd function in a new class and use :

    PHP:
    public function __cunstruct(Main $plugin) {
    $this->godweedzao $plugin;
    //im using my name in my examples, you can change it.
    }
     
  12. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    or you can write it in another files and then use that class in your main.

    also you can use OOP for doing this
     
  13. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Here you are 10 way to write cmd in plugin :)
     
  14. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    if solved set pref and if not, explain more please ;)
     
  15. Primus

    Primus Zombie Pigman

    Messages:
    749
    This is not a chat. Stop with the spam and if you truly want to contribute to solution of the issue, without being annoying, use the edit button.
     
  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.