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

[New API] Using ServerScheduler

Comments in 'Plugin Development' started by WinniePooh, Dec 5, 2014.

  1. WinniePooh
    Offline

    WinniePooh New Member

    Joined:
    Jun 12, 2014
    Posts:
    16
    Minecraft User:
    WinniePooh
    So, How can I get Schedule*Task ID after creating new task?

    PHP:
     $this->getServer->getScheduler()->scheduleDelayedTask(new Tasker($this),20*30);
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $this->getServer()->getScheduler()->scheduleDelayedTask($task = new Tasker($this), 20 30);
    $id $task->getTaskId();
    WinniePooh and EvolSoft like this.
  3. WinniePooh
    Offline

    WinniePooh New Member

    Joined:
    Jun 12, 2014
    Posts:
    16
    Minecraft User:
    WinniePooh
    Oh, It is really easy!
  4. WinniePooh
    Offline

    WinniePooh New Member

    Joined:
    Jun 12, 2014
    Posts:
    16
    Minecraft User:
    WinniePooh
    I'm sorry, but I've got another question. =(

    This task is going to be performed only ONE time (after 20*30 ticks), and how can I get my task's ID in task activation moment?

    PHP:
    ....                        
    $this->getServer()->getScheduler()->scheduleDelayedTask($task = new Tasker($this), 20 30);
    ....

    class 
    Tasker extends PluginTask {

        public function 
    onRun($currentTick) {
            
    //$this->getOwner()->tpaTaskCancel($id);
        
    }

    }


    Sorry for bad english!
  5. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    PHP:
    class Tasker extends PluginTask
    {
    fuction onRun($tick)
    {
    $this->getHandler()->cancel();
    }
    }
    Or
    PHP:
     class Tasker extends PluginTask{
    function 
    onRun($tick){
    $this->onCancel();
    }
    function 
    onCancel(){}
    }
    Last edited: Dec 5, 2014
    WinniePooh likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This doesn't work. I already told you. Use $this->owner->getServer()->getScheduler()->cancelTask($this->getTaskId()); are you trying to mislead people to a problem that confused you?
    Look at the docs. I added this warning:
    Code:
    WARNING: This is an internal function. Do not call this function.
  7. WinniePooh
    Offline

    WinniePooh New Member

    Joined:
    Jun 12, 2014
    Posts:
    16
    Minecraft User:
    WinniePooh
    Hm, I was tired yesterday :(
    And in fact, I'm creating own big essentialTP plugin, and when scheduler is canceling, my array with users wanted tpa must be cleaned. And my idea was in taking scheduler id and sending this id to main class as a key for array.
    Now I'm going to apply to my array (in main class) from class Tasker like $this->getOwner()->[my_array]. And I dont't need the id from class Tasker.
  8. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    I tried it and it works
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No it won't cancel the task. The onCancel() function will be called (because you called it yourself), but nothing else is change. If you use $this->getHandler()->cancel(), it only makes the task handler null, but the ServerScheduler still has that instance of Task. The correct method is to cancelTask(). If you don't believe me, look at the pull request. Shoghi merged it, and that's the best proof.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You are calling empty function onCancel(). Do you expect it to do anything?
    iJoshuaHD likes this.

Share This Page

Advertisement