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

Execution Timer

Comments in 'Plugin Development' started by Radix, Jul 25, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    How can I make my plugin execute what I want it to every 5 Mins?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make a subclass of PluginTask. In the onRun implementation, run the code you want. Make a new instance of it, pass it to the ServerScheduler->scheduleRepeatingTask function (get the ServerScheduler through Server->getScheduler()) with $ticks as 20 * 60 * 5 (20 ticks/s * 60 s/min * 5 min)
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    When I had this problem, this didn't help me until I got example. So here it is:

    In Main script add
    PHP:
    //Task is name of PHP file where you can add another information. ($this, $something) supports more values, but at least $this.
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this$something), 5*60*20);
    In Task.php;
    PHP:
    <?php

     
    namespace MyFolder;

    use 
    pocketmine\scheduler\PluginTask;
    //Task is name, also used before
    class Task extends PluginTask{
     public 
    $plugin;
     private 
    $something;
    //Don't forget to replace Main with name of first file
     
    public function __construct(Main $plugin$something){
    $this->something $something;
    parent::__construct($plugin);
    }
    public function 
    onRun($t){

    //Here, you can execute what you want
    }

    }
    Last edited: Jul 25, 2015
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Extend PluginTask, not PluginBase >.<
    CrazedMiner, hoyinm14mc and MCPEPIG like this.
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Edited && Fixed. Don't forget I'm just practicing PocketMine API on that, so I don't look at small mistakes like extending PluginTask/Base (Netbeans should tell me that PluginTask isn't used and I should solve it)
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well, a good IDE like PHPStorm tells you that Task instead of Plugin is expected to be passed into the schedule*Task functions.
  7. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Yes, but little sad thing about PHPStorm is that it is paid. (199$)
  8. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    Isn't it $99 USD?
  9. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Comodo IDE is best because it is free.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There are multiple ways that you can get it free.
  11. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02

Share This Page

Advertisement