help me __construct() must be an instance of

Discussion in 'Development' started by TheStepKla, Mar 23, 2020.

  1. TheStepKla

    TheStepKla Silverfish

    Messages:
    16
    help me please
    my logs
    Code:
    [12:16:19] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to KRTStudio\paycheck\paycheckre::__construct() must be an instance of KRTStudio\paycheck\Main, instance of KRTStudio\paycheck\paycheck given, called in E:\PocketMine-MP-3.11.5 - Roleplay - สำเนา - สำเนา\plugins\paycheckv1\src\KRTStudio\paycheck\paycheck.php on line 50" (EXCEPTION) in "plugins/paycheckv1/src/KRTStudio/paycheck/paycheckre" at line 37
    [12:16:19] [Server thread/DEBUG]: #0 plugins/paycheckv1/src/KRTStudio/paycheck/paycheck(50): KRTStudio\paycheck\paycheckre->__construct(object KRTStudio\paycheck\paycheck, object pocketmine\Player)
    [12:16:19] [Server thread/DEBUG]: #1 plugins/paycheckv1/src/KRTStudio/paycheck/paycheck(45): KRTStudio\paycheck\paycheck->RePaycheck(object pocketmine\Player)
    [12:16:19] [Server thread/DEBUG]: #2 src/pocketmine/scheduler/TaskHandler(134): KRTStudio\paycheck\paycheck->onRun(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #3 src/pocketmine/scheduler/TaskScheduler(176): pocketmine\scheduler\TaskHandler->run(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #4 src/pocketmine/plugin/PluginManager(643): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #5 src/pocketmine/Server(2380): pocketmine\plugin\PluginManager->tickSchedulers(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #6 src/pocketmine/Server(2143): pocketmine\Server->tick()
    [12:16:19] [Server thread/DEBUG]: #7 src/pocketmine/Server(1990): pocketmine\Server->tickProcessor()
    [12:16:19] [Server thread/DEBUG]: #8 src/pocketmine/Server(1584): pocketmine\Server->start()
    [12:16:19] [Server thread/DEBUG]: #9 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[71] E:\PocketMine-MP-3.11.5 - Roleplay - ............... - ...............\, string[79] E:\PocketMine-MP-3.11.5 - Roleplay - ............... - ...............\plugins\)
    [12:16:19] [Server thread/DEBUG]: #10 src/pocketmine/PocketMine(296): pocketmine\server()
    [12:16:19] [Server thread/DEBUG]: #11 (11): require(string[126] phar://E:/PocketMine-MP-3.11.5 - Roleplay - ............... - .............../Po)
    my code paycheck
    Code:
    class paycheck extends Task {
       
        private $plugin;
        private $player;
       
        public function __construct(Main $plugin, Player $player){
            $this->plugin = $plugin;
            $this->player = $player;
          
        }
    
        public function onRun(int $currentTick){
            $player = $this->player;
            $this->ItemOnlineMain($player);
            $this->RePaycheck($player);
        }
       
        public function RePaycheck($player){
            $player = $this->player;
            $this->plugin->getScheduler()->scheduleRepeatingTask(new paycheckre($this, $player), 1200);
        }
       
        public function ItemOnlineMain($player){
            $player = $this->player;
            $player->getInventory()->addItem(Item::get(351, 10, 1)->setCustomName("§aItem §9online"));
            $player->sendPopup("§9You have §aItem §9online");
        }
    }
    my code paycheckre
    Code:
    class paycheckre extends Task {
       
        private $main;
        private $player;
       
        public function __construct(Main $main, Player $player){
            $this->main = $main;
            $this->player = $player;
        }
    
        public function onRun(int $currentTick){
            $player = $this->player;
            $this->ItemOnline($player);
        }
       
        public function ItemOnline($player){
            $player->getInventory()->addItem(Item::get(351, 10, 1)->setCustomName("§aItem §9online"));
            $player->sendPopup("§9You have §aItem §9online");
        }
    }
     
    Last edited: Mar 24, 2020
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,078
    GitHub:
    HimbeersaftLP
    getScheduler is a method of PluginBase, but you're in a task class. However since you passed your plugin to the class, you can just use $this->main->getScheduler() instead.
     
    GamakCZ likes this.
  3. TheStepKla

    TheStepKla Silverfish

    Messages:
    16
    help me please
    my logs
    Code:
    [12:16:19] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to KRTStudio\paycheck\paycheckre::__construct() must be an instance of KRTStudio\paycheck\Main, instance of KRTStudio\paycheck\paycheck given, called in E:\PocketMine-MP-3.11.5 - Roleplay - สำเนา - สำเนา\plugins\paycheckv1\src\KRTStudio\paycheck\paycheck.php on line 50" (EXCEPTION) in "plugins/paycheckv1/src/KRTStudio/paycheck/paycheckre" at line 37
    [12:16:19] [Server thread/DEBUG]: #0 plugins/paycheckv1/src/KRTStudio/paycheck/paycheck(50): KRTStudio\paycheck\paycheckre->__construct(object KRTStudio\paycheck\paycheck, object pocketmine\Player)
    [12:16:19] [Server thread/DEBUG]: #1 plugins/paycheckv1/src/KRTStudio/paycheck/paycheck(45): KRTStudio\paycheck\paycheck->RePaycheck(object pocketmine\Player)
    [12:16:19] [Server thread/DEBUG]: #2 src/pocketmine/scheduler/TaskHandler(134): KRTStudio\paycheck\paycheck->onRun(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #3 src/pocketmine/scheduler/TaskScheduler(176): pocketmine\scheduler\TaskHandler->run(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #4 src/pocketmine/plugin/PluginManager(643): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #5 src/pocketmine/Server(2380): pocketmine\plugin\PluginManager->tickSchedulers(integer 1685)
    [12:16:19] [Server thread/DEBUG]: #6 src/pocketmine/Server(2143): pocketmine\Server->tick()
    [12:16:19] [Server thread/DEBUG]: #7 src/pocketmine/Server(1990): pocketmine\Server->tickProcessor()
    [12:16:19] [Server thread/DEBUG]: #8 src/pocketmine/Server(1584): pocketmine\Server->start()
    [12:16:19] [Server thread/DEBUG]: #9 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[71] E:\PocketMine-MP-3.11.5 - Roleplay - ............... - ...............\, string[79] E:\PocketMine-MP-3.11.5 - Roleplay - ............... - ...............\plugins\)
    [12:16:19] [Server thread/DEBUG]: #10 src/pocketmine/PocketMine(296): pocketmine\server()
    [12:16:19] [Server thread/DEBUG]: #11 (11): require(string[126] phar://E:/PocketMine-MP-3.11.5 - Roleplay - ............... - .............../Po)
    my code paycheck
    Code:
    class paycheck extends Task {
        
        private $plugin;
        private $player;
        
        public function __construct(Main $plugin, Player $player){
            $this->plugin = $plugin;
            $this->player = $player;
            
        }
    
        public function onRun(int $currentTick){
            $player = $this->player;
            $this->ItemOnlineMain($player);
            $this->RePaycheck($player);
        }
        
        public function RePaycheck($player){
            $player = $this->player;
            $this->plugin->getScheduler()->scheduleRepeatingTask(new paycheckre($this, $player), 1200);
        }
        
        public function ItemOnlineMain($player){
            $player = $this->player;
            $player->getInventory()->addItem(Item::get(351, 10, 1)->setCustomName("§aItem §9online"));
            $player->sendPopup("§9You have §aItem §9online");
        }
    }
    my code paycheckre
    Code:
    class paycheckre extends Task {
        
        private $main;
        private $player;
        
        public function __construct(Main $main, Player $player){
            $this->main = $main;
            $this->player = $player;
        }
    
        public function onRun(int $currentTick){
            $player = $this->player;
            $this->ItemOnline($player);
        }
        
        public function ItemOnline($player){
            $player->getInventory()->addItem(Item::get(351, 10, 1)->setCustomName("§aItem §9online"));
            $player->sendPopup("§9You have §aItem §9online");
        }
    }
     
  4. TheStepKla

    TheStepKla Silverfish

    Messages:
    16
    thank but I have new bug!
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,078
    GitHub:
    HimbeersaftLP
    You paycheckre class expects your plugin's main class as the first argument to its constructor, but you're passing a Task object.
    PHP:
    public function __construct(Main $mainPlayer $player){ // wants a Main object
    $this->plugin->getScheduler()->scheduleRepeatingTask(new paycheckre($this$player), 1200); // But $this refers to a Task
    You need to pass your plugin's main class instead:
    PHP:
    $this->plugin->getScheduler()->scheduleRepeatingTask(new paycheckre($this->plugin$player), 1200);
     
    GamakCZ likes this.
  6. TheStepKla

    TheStepKla Silverfish

    Messages:
    16
    thank
     
    HimbeersaftLP likes this.

Share This Page

  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.