PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
TaskHandler.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17 
18  *
19  *
20 */
21 
22 namespace pocketmine\scheduler;
23 
25 
27 
29  protected $task;
30 
32  protected $taskId;
33 
35  protected $delay;
36 
38  protected $period;
39 
41  protected $nextRun;
42 
44  protected $cancelled = false;
45 
47  public $timings;
48 
49  public $timingName = null;
50 
58  public function __construct($timingName, Task $task, $taskId, $delay = -1, $period = -1){
59  $this->task = $task;
60  $this->taskId = $taskId;
61  $this->delay = $delay;
62  $this->period = $period;
63  $this->timingName = $timingName === null ? "Unknown" : $timingName;
64  $this->timings = Timings::getPluginTaskTimings($this, $period);
65  }
66 
70  public function isCancelled(){
71  return $this->cancelled === true;
72  }
73 
77  public function getNextRun(){
78  return $this->nextRun;
79  }
80 
84  public function setNextRun($ticks){
85  $this->nextRun = $ticks;
86  }
87 
91  public function getTaskId(){
92  return $this->taskId;
93  }
94 
98  public function getTask(){
99  return $this->task;
100  }
101 
105  public function getDelay(){
106  return $this->delay;
107  }
108 
112  public function isDelayed(){
113  return $this->delay > 0;
114  }
115 
119  public function isRepeating(){
120  return $this->period > 0;
121  }
122 
126  public function getPeriod(){
127  return $this->period;
128  }
129 
134  public function cancel(){
135  if(!$this->isCancelled()){
136  $this->task->onCancel();
137  }
138  $this->remove();
139  }
140 
141  public function remove(){
142  $this->cancelled = true;
143  $this->task->setHandler(null);
144  }
145 
149  public function run($currentTick){
150  $this->task->onRun($currentTick);
151  }
152 
156  public function getTaskName(){
157  if($this->timingName !== null){
158  return $this->timingName;
159  }
160 
161  return get_class($this->task);
162  }
163 }
__construct($timingName, Task $task, $taskId, $delay=-1, $period=-1)
Definition: TaskHandler.php:58
static getPluginTaskTimings(TaskHandler $task, $period)
Definition: Timings.php:135