1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to get AsyncTask ID?

Discussion in 'Development' started by zKoz210, Jan 23, 2018.

  1. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
    For example, in ordinary tasks to get ID this way, but what about Async?

    $task = self::$plugin->getServer()->getScheduler()->scheduleDelayedTask(new TPTask(self::$plugin, $player), 20 * 60 * 5);
    $task->getTaskId();
     
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The question is, why do you want to? Remember that you can't schedule AsyncTask like you cancel a repeating task.
     
  4. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    AsyncServerStatus;

    use 
    pocketmine\scheduler\PluginTask;

    class 
    AsyncServerTask extends PluginTask
    {
        
    /** @var AsyncServerStatus */
        
    private $plugin;
       
        private 
    $asyncTaskId = -1;

        public function 
    __construct(AsyncServerStatus $plugin)
        {
            
    parent::__construct($plugin);
            
    $this->plugin $plugin;
        }

        public function 
    onRun(int $currentTick): void
        
    {
            if (!
    $this->plugin->getServer()->getScheduler()->isQueued($this->asyncTaskId)) {
                
    // new AsyncTask
                
    $this->asyncTaskId 202020020// ID Task
            
    }
        }
    }
     
  5. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What are you trying to do?
     
    SuperStulle007 likes this.
  7. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
    Run asynchronous tasks on time. And new should not be started if the old is not complete
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why don't you toggle a boolean field in AsyncTask->onCompletion? You can store the AsyncServerTask instance with the task using AsyncTask->storeLocal.
     
  9. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
    In my case it does not help. Why not return the TaskID?
     
  10. zKoz210

    zKoz210 Spider

    Messages:
    11
    GitHub:
    zkoz210
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.