getScheduler() публичный Метод

public getScheduler ( ) : ServerScheduler
Результат pocketmine\scheduler\ServerScheduler
Пример #1
0
 public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50)
 {
     $this->server = $server;
     $this->workers = [];
     $this->password = (string) $password;
     $this->server->getLogger()->info("Starting remote control listener");
     if ($this->password === "") {
         $this->server->getLogger()->critical("RCON can't be started: Empty password");
         return;
     }
     $this->threads = (int) max(1, $threads);
     $this->clientsPerThread = (int) max(1, $clientsPerThread);
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if ($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)) {
         $this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
         $this->threads = 0;
         return;
     }
     socket_set_block($this->socket);
     for ($n = 0; $n < $this->threads; ++$n) {
         $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
     }
     socket_getsockname($this->socket, $addr, $port);
     $this->server->getLogger()->info("RCON running on {$addr}:{$port}");
     $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "check"]), 3);
 }
Пример #2
0
 public function __construct(PlayHarder $plugin)
 {
     if (self::$instance == null) {
         self::$instance = $this;
     }
     $this->server = Server::getInstance();
     $this->plugin = $plugin;
     $this->server->getScheduler()->scheduleRepeatingTask(new AutoUnloadTask($this), 12000);
 }
Пример #3
0
 public function doUpgrade()
 {
     if (!$this->isupdating) {
         $this->isupdating = true;
         $this->server->getScheduler()->scheduleAsyncTask(new Upgrader($this->updateInfo['download_url'], $this->updateInfo['fingerprint'], "phar://" . $this->server->getDataPath() . "ClearSkyNewVersion" . "phar"));
         //Is an .phar needed?
     } else {
         Command::broadcastCommandMessage($sender, new TranslationContainer("commands.upgrade.isUpdating"));
     }
 }
Пример #4
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin->isEnabled()) {
         $plugin->getPluginLoader()->disablePlugin($plugin);
         $this->server->getScheduler()->cancelTasks($plugin);
         HandlerList::unregisterAll($plugin);
         foreach ($plugin->getDescription()->getPermissions() as $perm) {
             $this->removePermission($perm);
         }
     }
 }
Пример #5
0
 public function triggerGarbageCollector()
 {
     Timings::$garbageCollectorTimer->startTiming();
     if ($this->garbageCollectionAsync) {
         $size = $this->server->getScheduler()->getAsyncTaskPoolSize();
         for ($i = 0; $i < $size; ++$i) {
             $this->server->getScheduler()->scheduleAsyncTaskToWorker(new GarbageCollectionTask(), $i);
         }
     }
     $cycles = gc_collect_cycles();
     Timings::$garbageCollectorTimer->stopTiming();
     return $cycles;
 }
Пример #6
0
 /**
  * @param Server $server
  */
 public function onCompletion(Server $server)
 {
     /** @var Loader $esspe */
     $esspe = $server->getPluginManager()->getPlugin("EssentialsPE");
     if ($esspe->getDescription()->getVersion() < ($v = $this->getResult()["version"])) {
         $continue = true;
         $message = TextFormat::AQUA . "[EssentialsPE]" . TextFormat::GREEN . " A new " . TextFormat::YELLOW . $this->build . TextFormat::GREEN . " version of EssentialsPE found! Version: " . TextFormat::YELLOW . $v . TextFormat::GREEN . ($this->install !== true ? "" : ", " . TextFormat::LIGHT_PURPLE . "Installing...");
     } else {
         $continue = false;
         $message = TextFormat::AQUA . "[EssentialsPE]" . TextFormat::YELLOW . " No new version found, you're using the latest version of EssentialsPE";
     }
     $esspe->broadcastUpdateAvailability($message);
     if ($continue && $this->install) {
         $server->getScheduler()->scheduleAsyncTask($task = new UpdateInstallTask($esspe, $this->getResult()["downloadURL"], $server->getPluginPath(), $v));
         $esspe->updaterDownloadTask = $task;
     }
 }
Пример #7
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin->isEnabled()) {
         try {
             $plugin->getPluginLoader()->disablePlugin($plugin);
         } catch (\Exception $e) {
             $logger = Server::getInstance()->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
         $this->server->getScheduler()->cancelTasks($plugin);
         HandlerList::unregisterAll($plugin);
         foreach ($plugin->getDescription()->getPermissions() as $perm) {
             $this->removePermission($perm);
         }
     }
 }
Пример #8
0
 public function collectTasks()
 {
     Timings::$schedulerAsyncTimer->startTiming();
     foreach ($this->tasks as $task) {
         if (!$task->isGarbage()) {
             $task->checkProgressUpdates($this->server);
         }
         if ($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()) {
             if (!$task->hasCancelledRun()) {
                 $task->onCompletion($this->server);
                 $this->server->getScheduler()->removeLocalComplex($task);
             }
             $this->removeTask($task);
         } elseif ($task->isTerminated() or $task->isCrashed()) {
             $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": Task crashed");
             $this->removeTask($task, true);
         }
     }
     Timings::$schedulerAsyncTimer->stopTiming();
 }
Пример #9
0
 protected function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             if (PHP_INT_SIZE === 8) {
                 $x = $index >> 32 << 32 >> 32;
                 $z = ($index & 4294967295.0) << 32 >> 32;
             } else {
                 list($x, $z) = explode(":", $index);
                 $x = (int) $x;
                 $z = (int) $z;
             }
             if (ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getId() . ":" . $index)) !== false) {
                 /** @var Player[] $players */
                 foreach ($players as $player) {
                     if ($player->isConnected() and isset($player->usedChunks[$index])) {
                         $player->sendChunk($x, $z, $cache);
                     }
                 }
                 unset($this->chunkSendQueue[$index]);
             } else {
                 $this->chunkSendTasks[$index] = true;
                 $this->timings->syncChunkSendPrepareTimer->startTiming();
                 $task = $this->provider->requestChunkTask($x, $z);
                 if ($task instanceof AsyncTask) {
                     $this->server->getScheduler()->scheduleAsyncTask($task);
                 }
                 $this->timings->syncChunkSendPrepareTimer->stopTiming();
             }
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }
Пример #10
0
 public function generateChunk($x, $z, $force = false)
 {
     if (count($this->chunkGenerationQueue) >= $this->chunkGenerationQueueSize and !$force) {
         return;
     }
     if (!isset($this->chunkGenerationQueue[$index = Level::chunkHash($x, $z)])) {
         Timings::$generationTimer->startTiming();
         $this->chunkGenerationQueue[$index] = true;
         $task = new GenerationTask($this, $this->getChunk($x, $z, true));
         $this->server->getScheduler()->scheduleAsyncTask($task);
         Timings::$generationTimer->stopTiming();
     }
 }
Пример #11
0
 protected function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             Level::getXZ($index, $x, $z);
             if (ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getID() . ":" . $index)) !== false) {
                 /** @var Player[] $players */
                 foreach ($players as $player) {
                     if (isset($player->usedChunks[$index])) {
                         $player->sendChunk($x, $z, $cache);
                     }
                 }
                 unset($this->chunkSendQueue[$index]);
             } else {
                 $this->chunkSendTasks[$index] = true;
                 $task = $this->provider->requestChunkTask($x, $z);
                 if ($task instanceof AsyncTask) {
                     $this->server->getScheduler()->scheduleAsyncTask($task);
                 }
             }
         }
     }
 }
Пример #12
0
 public function generateChunk($x, $z, $force = \false)
 {
     if (\count($this->chunkGenerationQueue) >= $this->chunkGenerationQueueSize and !$force) {
         return;
     }
     if (!isset($this->chunkGenerationQueue[$index = \PHP_INT_SIZE === 8 ? ($x & 0xffffffff) << 32 | $z & 0xffffffff : $x . ":" . $z])) {
         Timings::$generationTimer->startTiming();
         $this->chunkGenerationQueue[$index] = \true;
         $task = new GenerationTask($this, $this->getChunk($x, $z, \true));
         $this->server->getScheduler()->scheduleAsyncTask($task);
         Timings::$generationTimer->stopTiming();
     }
 }
Пример #13
0
 private function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             Level::getXZ($index, $x, $z);
             $this->chunkSendTasks[$index] = true;
             // Gets chunks from disk or cache if it can
             if (isset($this->chunkCache[$x . ":" . $z]) or $this->loadChunkFromDisk($x, $z)) {
                 foreach ($players as $player) {
                     // Found chunk? Call special function to send just the payload
                     $player->sendBatchedChunk($x, $z, $this->chunkCache[$x . ":" . $z]);
                 }
                 unset($this->chunkSendQueue[$index]);
                 unset($this->chunkSendTasks[$index]);
                 $this->server->chunkUsedTimes[$this->getName()][$x . ":" . $z] = time();
                 continue;
             }
             $this->timings->syncChunkSendPrepareTimer->startTiming();
             $task = $this->provider->requestChunkTask($x, $z);
             if ($task !== null) {
                 $this->server->getScheduler()->scheduleAsyncTask($task);
             }
             $this->timings->syncChunkSendPrepareTimer->stopTiming();
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }
Пример #14
0
 public function addLightning(Vector3 $pos, $autoRemoveTime = 3)
 {
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $pos->getX()), new Double("", $pos->getY()), new Double("", $pos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]);
     $chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false);
     $lightning = new Lightning($chunk, $nbt);
     $lightning->spawnToAll();
     $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask([$lightning, "close"]), $autoRemoveTime * 20);
 }
Пример #15
0
 public function generateChunk($x, $z, $force = \false)
 {
     if (\count($this->chunkGenerationQueue) >= $this->chunkGenerationQueueSize and !$force) {
         return;
     }
     if (!isset($this->chunkGenerationQueue[$index = ($x & 4294967295.0) << 32 | $z & 4294967295.0])) {
         Timings::$generationTimer->startTiming();
         $this->chunkGenerationQueue[$index] = \true;
         $task = new GenerationTask($this, $this->getChunk($x, $z, \true));
         $this->server->getScheduler()->scheduleAsyncTask($task);
         Timings::$generationTimer->stopTiming();
     }
 }