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

Plugin help

Discussion in 'Development' started by Levi, Aug 9, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I'm getting error with my plugin
    error:

    Code:
    03:13:29 [CRITICAL] Unhandled exception executing command 'lobby' in lobby: Argument 1 passed to Core\Tasks\LobbyTask::__construct() must be an instance of Core\Main, instance of Core\Commands\Lobby given, called in /root/l/plugins/PrisonCore - Copy/src/Core/Commands/Lobby.php on line 24
    03:13:29 [CRITICAL] TypeError: "Argument 1 passed to Core\Tasks\LobbyTask::__construct() must be an instance of Core\Main, instance of Core\Commands\Lobby given, called in /root/l/plugins/PrisonCore - Copy/src/Core/Commands/Lobby.php on line 24" (EXCEPTION) in "/plugins/PrisonCore - Copy/src/Core/Tasks/LobbyTask" at line 15
    
    lobbytask:

    PHP:
    <?php

    namespace Core\Tasks;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Player;
    use 
    Core\Main;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    Core\Commands\Lobby;

    class 
    LobbyTask extends PluginTask{
      
      
        public function 
    __construct(Main $mainPlayer $player){
          
            
    parent::__construct($main$player);
          
            
    $this->main $main;
            
    $this->seconds 3;
            
    $this->player $player;
          
        }
    lobby.php

    PHP:

    <?php

    namespace Core\Commands;

    use 
    Core\Main;
    use 
    pocketmine\command\{CommandSenderCommand};
    use 
    Core\Tasks\LobbyTask;
    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    Lobby extends Command{

        public function 
    __construct(Main $main)
        {
            
    parent::__construct("lobby"$main);
            
    $this->main $main;
          
        }

        public function 
    execute(CommandSender $sender$commandLabel, array $args){
                    
    $player $sender;
                    
    $task = new LobbyTask($this$player);
                     
    $this->main->getServer()->getScheduler()->scheduleRepeatingTask($task1*20);
                    return 
    true;
        }
    }
          
        }
     
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Where did you call your lobbytask?
    Please show it
     
    Levi likes this.
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Opps my bad I missed it...
    //lobby task:
    public function __construct(Lobby $main, Player $player){ //Your class called Lobby not Main

    parent::__construct($main, $player);

    $this->main = $main;
    $this->seconds = 3;
    $this->player = $player;[/PHP]
     
    Last edited by a moderator: Aug 9, 2017
    Levi likes this.
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    uhhh..my bad up there...
    PHP:
    //Lobby task
    public function __construct(Lobby $main Player $player) {  //Your class is called Lobby not Main
    parent::__construct($main $player);

    $this->main $main;
    $this->seconds 3;
    $this->player $player;
    }
     
    Levi likes this.
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    thanks, so is everything else fine ?
     
    Last edited: Aug 9, 2017
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    PHP:

    <?php

    namespace Core\Commands;

    use 
    Core\Main;
    use 
    pocketmine\command\{CommandSenderCommand};
    use 
    Core\Tasks\LobbyTask;
    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    Lobby extends Command{

        public function 
    __construct(Main $main)
        {
            
    parent::__construct("lobby"$main);
            
    $this->main $main;
          
        }

        public function 
    execute(CommandSender $sender$commandLabel, array $args){
                    
    $player $sender;
                    
    $task = new LobbyTask($this->main$player); // not $this but $this->main
                     
    $this->main->getServer()->getScheduler()->scheduleRepeatingTask($task1*20);
                    return 
    true;
        }
    }
          
        }
     
  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.