Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need help with scheduleRepeatingTask

Comments in 'Plugin Development' started by Lexodexo, Jan 23, 2016.

  1. Lexodexo
    Offline

    Lexodexo New Member

    Joined:
    Jan 4, 2016
    Posts:
    11
    Minecraft User:
    Henning
    Hi, when i start my plugin, this happens in consol:

    Code:
    system> Enabling News v1
    notice> InvalidArgumentException: "Argument 1 passed to News\shownews::__construct() must be an instance of News\Plugin, instance of News\Main given, called in /bla/bub/PocketMine/plugins/News/src/News/Main.php on line 20 and defined" (E_RECOVERABLE_ERROR) in "/News/src/News/Main" at line 42
    Disabling News v1
    
    And here is my code:

    Code:
    <?php
    
    namespace News;
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\Server;
    use pocketmine\scheduler;
    use pocketmine\scheduler\PluginTask;
    use pocketmine\event;
    use pocketmine\event\Listener;
    use pocketmine\utils\TextFormat as Color;
    use pocketmine\event\player\PlayerChatEvent;
    use pocketmine\command\CommandSender;
    use pocketmine\command\Command;
    use pocketmine\Player;
    
    class Main extends PluginBase implements Listener{
        public function onEnable(){
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
                    $this->getServer()->getScheduler()->scheduleRepeatingTask(new shownews($this), 20);
            $this->saveDefaultConfig();
                    $this->zeit = 0;
            $this->getLogger()->info(Color::GREEN . "News");
        }
        public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
            $cmd = strtolower($command->getName());
            switch ($cmd){
                case "news":
                    if (!($sender instanceof Player)){
                        $sender->sendMessage($this->getConfig()->get("news1"));
                        $sender->sendMessage($this->getConfig()->get("news2"));
                        $sender->sendMessage($this->getConfig()->get("news3"));
                        $sender->sendMessage($this->getConfig()->get("news4"));
                        $sender->sendMessage($this->getConfig()->get("news5"));
                        return true;
                    }
                }
            }
    }
    
    class shownews extends PluginTask implements Listener{
        public function __construct(Plugin $owner){
                parent::__construct($owner);
        }
       
        public function onRun($currentTick){
           
            if($this->getOwner()->zeit < 5){
                foreach($this->getOwner()->getServer()->getLevelByName("spawn")->getPlayers() as $player){
                    $player->sendTip($this->getConfig()->get("news1"));
                }
                $this->getOwner()->zeit + 1;
                return true;
            }
            if($this->getowner()->zeit < 10){
                foreach($this->getOwner()->getServer()->getLevelByName("spawn")->getPlayers() as $player){
                    $player->sendTip($this->getConfig()->get("news2"));
                }
                $this->getOwner()->zeit + 1;
                return true;
            }
            if($this->getowner()->zeit < 15){
                foreach($this->getOwner()->getServer()->getLevelByName("spawn")->getPlayers() as $player){
                    $player->sendTip($this->getConfig()->get("news3"));
                }
                $this->getOwner()->zeit + 1;
                return true;
            }
            if($this->getowner()->zeit < 20){
                foreach($this->getOwner()->getServer()->getLevelByName("spawn")->getPlayers() as $player){
                    $player->sendTip($this->getConfig()->get("news4"));
                }
                $this->getOwner()->zeit + 1;
                return true;
            }
            if($this->getowner()->zeit < 25){
                foreach($this->getOwner()->getServer()->getLevelByName("spawn")->getPlayers() as $player){
                    $player->sendTip($this->getConfig()->get("news5"));
                }
                $this->getOwner()->zeit + 1;
                return true;
            }
            if($this->getOwner()->zeit == 25){
                $this->getOwner()->zeit = 0;
            }
        }    
    }
       
    ?>
    can you plz help me?;)
    Sry for my bad English:confused:
  2. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    why you should use Listener in youre timer Task? try to delete the "implements Listener" in the PluginTask class :D
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    this
    PHP:
    public function __construct(Plugin/**/ $owner){//
    parent::__construct($owner);
    }
    should be
    PHP:
    public function __construct(Main $owner){
    parent::__construct($owner);
    }
    Vaivez66 and AndrewBit like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have to `use pocketmine\plugin\PluginTask;` in your Listener class.

    Also, in case you don't, remember that you have to put every class in its independent file.

Share This Page

Advertisement