예제 #1
0
 /**
  * @param Task $task
  * @param      $delay
  * @param      $period
  *
  * @return null|TaskHandler
  *
  * @throws PluginException
  */
 private function addTask(Task $task, $delay, $period)
 {
     if ($task instanceof PluginTask) {
         if (!$task->getOwner() instanceof Plugin) {
             throw new PluginException("Invalid owner of PluginTask " . get_class($task));
         } elseif (!$task->getOwner()->isEnabled()) {
             throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled");
         }
     } elseif ($task instanceof CallbackTask and Server::getInstance()->getProperty("settings.deprecated-verbose", true)) {
         $callable = $task->getCallable();
         if (is_array($callable)) {
             if (is_object($callable[0])) {
                 $taskName = "Callback#" . get_class($callable[0]) . "::" . $callable[1];
             } else {
                 $taskName = "Callback#" . $callable[0] . "::" . $callable[1];
             }
         } else {
             $taskName = "Callback#" . $callable;
         }
         Server::getInstance()->getLogger()->warning("A plugin attempted to register a deprecated CallbackTask ({$taskName})");
     }
     if ($delay <= 0) {
         $delay = -1;
     }
     if ($period <= -1) {
         $period = -1;
     } elseif ($period < 1) {
         $period = 1;
     }
     return $this->handle(new TaskHandler(get_class($task), $task, $this->nextId(), $delay, $period));
 }
 /**
  * @param Task $task
  * @param      $delay
  * @param      $period
  *
  * @return null|TaskHandler
  *
  * @throws PluginException
  */
 private function addTask(Task $task, $delay, $period)
 {
     if ($task instanceof PluginTask) {
         if (!$task->getOwner() instanceof Plugin) {
             throw new PluginException("Invalid owner of PluginTask " . get_class($task));
         } elseif (!$task->getOwner()->isEnabled()) {
             throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled");
         }
     }
     if ($delay <= 0) {
         $delay = -1;
     }
     if ($period <= -1) {
         $period = -1;
     } elseif ($period < 1) {
         $period = 1;
     }
     return $this->handle(new TaskHandler(get_class($task), $task, $this->nextId(), $delay, $period));
 }
예제 #3
0
 /**
  * @param int $currentTick
  */
 public function run($currentTick)
 {
     $this->task->onRun($currentTick);
 }
예제 #4
0
 /**
  * @param Task $task
  * @param      $delay
  * @param      $period
  *
  * @return null|TaskHandler
  *
  * @throws PluginException
  */
 private function addTask(Task $task, $delay, $period)
 {
     if ($task instanceof PluginTask) {
         if (!$task->getOwner() instanceof Plugin) {
             throw new PluginException("Invalid owner of PluginTask " . \get_class($task));
         } elseif (!$task->getOwner()->isEnabled()) {
             throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled");
         }
     }
     if ($delay <= 0) {
         $delay = -1;
     }
     if ($period <= -1) {
         $period = -1;
     } elseif ($period < 1) {
         $period = 1;
     }
     if ($task instanceof CallbackTask) {
         $callable = $task->getCallable();
         if (\is_array($callable)) {
             if (\is_object($callable[0])) {
                 $taskName = "Callback#" . \get_class($callable[0]) . "::" . $callable[1];
             } else {
                 $taskName = "Callback#" . $callable[0] . "::" . $callable[1];
             }
         } else {
             $taskName = "Callback#" . $callable;
         }
     } else {
         $taskName = \get_class($task);
     }
     return $this->handle(new TaskHandler($taskName, $task, $this->nextId(), $delay, $period));
 }