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

New API Schedule functions

Comments in 'Plugin Development' started by luca28pet, Aug 24, 2014.

  1. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Hi, I am porting an old Hunger Games plugin for the new API. But I can't figure out of what should be this in the new API:
    PHP:
    $this->api->schedule(1200, array($this"minuteSchedule"), array(), true);
    Can anyone help me?
    By The way, it is for the timer of the plugin.
    Jon likes this.
  2. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    This should work
    PHP:
    use pocketmine\scheduler\PluginTask;
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new minuteSchedule($this), 1200);
    Last edited: Aug 24, 2014
    Dutok and luca28pet like this.
  3. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I'll try with this thanks!
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You told him nothing. You didn't even tell him another class is required.
  5. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Yes, i noticed that from the crashes, so, the only way to do that timer is to create another class?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, that is the easiest way for him.
    luca28pet likes this.
  7. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Ok, thanks.
  8. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    So to show you the FULL example:
    PHP:
    <?php
     
    namespace Example;
     
     
    use 
    pocketmine\utils\TextFormat as MT;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\server;
     
     
     
    class 
    Example extends PluginBase
    {
           
           
            public function 
    onEnable()
            {
                    
    $this->getLogger()->info(MT::BLUE "[MineTox]" MT::RED "The Scheduler" MT::BLUE " has been loaded");
                    
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new ExampleTask($this), 1200);
            }
           
     
    }
     
    class 
    ExampleTask extends PluginTask //Create a new Class
    {
     
        public function 
    __construct(Example $plugin){
        }
     
        public function 
    onRun($currentTick//Create a function like this
            
    {
            
    Server::getInstance()->broadcastMessage("This Message will broadcast every Second!");
            }
           
    }
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make it into two files, or you'll be rejected for bad practice (bad format: only one class/interface/trait per file).
    Jon likes this.
  10. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    So this was only an Example :D
    Last edited: Aug 29, 2014

Share This Page

Advertisement