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

Solved Need help with Scheduler

Comments in 'Plugin Development' started by cake23, Feb 8, 2016.

  1. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Hey! I need help with the scheduleRepeatingTask!
    Main-File:
    PHP:
    <?php

    namespace SchedulerTest;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener {
       
        public function 
    onEnable() {
            
    $this->getLogger()->info("activated!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
        public function 
    onJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), 20);
        }
       
    }
    And the Task.php-File:
    PHP:
    <?php

    namespace Task;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat as Color;

    class 
    Task extends PluginTask {
       
        public function 
    __construct(\pocketmine\plugin\Plugin $owner) {
            
    parent::__construct($owner);
            
    $this->owner $owner;
        }
       
        public function 
    onRun($currentTick) {
            
    $this->getOwner()->getServer()->getLogger()->info("Test!");
        }
       
    }
    And i get this Error:
    Code:
    [20:33:12] critical> "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'SchedulerTest v1.0.0': Class SchedulerTest\Task not found on SchedulerTest\Main
    [20:33:12] critical> ClassNotFoundException: "Class SchedulerTest\Task not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 131
    
    Can anyone help me? :/ I am sorry, i am new in creating a Task....
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Remember you need to import the namespace\to\your\task\file; namespace like you did the PocketMine namespaces.
    cake23 likes this.
  3. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    So i need to change the namespace in my task.php-file to the same namespace in my main-file? (namespace SchedulerTest;)
  4. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    No, you need to enter the namespace of your task.php file into your main file.
    PHP:
    use namespace\to\task.php;
    Alternatively, you could include your Task class inside the main file, and avoid the complexity of a second PHP file.
    cake23 likes this.
  5. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Oh okay, thanks!
    HotFireyDeath likes this.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Since when with ".php"?
    cake23 likes this.
  7. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    My message "Namespace to task.php" does not imply that it must end with .php.
    I said namespace to that specific file, so you would enter the corresponding namespace and not the file path.
    cake23 likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should be thinking about the class name, not the file name.
    HotFireyDeath and cake23 like this.

Share This Page

Advertisement