public function run() { $this->reds = $this->plugin->reds; $this->blues = $this->plugin->blues; if (count($this->reds) < 5 && count($this->blues) < 5) { $this->gst = Tasks::scheduleRepeatingTask(new Tasks\GameStartTask($this), 20)->getTaskId(); Tasks::cancelTask($this->gwt); } else { $this->gwt = Tasks::scheduleRepeatingTask(new Tasks\GameWaitingTask($this), 15)->getTaskId(); } }
public function onRun($tick) { $this->seconds = $this->seconds - 1; foreach ($this->plugin->reds as $r) { foreach ($this->plugin->blues as $b) { foreach ($this->plugin->yml["items"] as $i) { Server::getInstance()->getPlayer($r)->sendPopup("§eThe game will start in {$this->seconds} second(s)!"); Server::getInstance()->getPlayer($b)->sendPopup("§eThe game will start in {$this->seconds} second(s)!"); if ($this->seconds == 1) { Server::getInstance()->getPlayer($r)->teleport(new Vector3($this->plugin->yml["red_enter_x"], $this->plugin->yml["red_enter_y"], $this->plugin->yml["red_enter_z"])); Server::getInstance()->getPlayer($b)->teleport(new Vector3($this->plugin->yml["blue_enter_x"], $this->plugin->yml["blue_enter_y"], $this->plugin->yml["blue_enter_z"])); Server::getInstance()->getPlayer($r)->getInventory()->addItem(Item::get($i)); Server::getInstance()->getPlayer($b)->getInventory()->addItem(Item::get($i)); $this->plugin->gameStarted = true; $this->seconds = 15; Tasks::cancelTask($this->getTaskId()); } } } } }
/** * Tries to execute a server tick */ private function tick() { $tickTime = microtime(true); if ($tickTime - $this->nextTick < -0.025) { //Allow half a tick of diff return false; } Timings::$serverTickTimer->startTiming(); ++$this->tickCounter; $this->checkConsole(); Timings::$connectionTimer->startTiming(); $this->network->processInterfaces(); if ($this->rcon !== null) { $this->rcon->check(); } Timings::$connectionTimer->stopTiming(); Timings::$schedulerTimer->startTiming(); $this->scheduler->mainThreadHeartbeat($this->tickCounter); Timings::$schedulerTimer->stopTiming(); $this->checkTickUpdates($this->tickCounter, $tickTime); foreach ($this->players as $player) { $player->checkNetwork(); } if (($this->tickCounter & 0b1111) === 0) { $this->titleTick(); $this->maxTick = 20; $this->maxUse = 0; if (($this->tickCounter & 0b111111111) === 0) { try { $this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5)); if ($this->queryHandler !== null) { $this->queryHandler->regenerateInfo(); } } catch (\Exception $e) { if ($this->logger instanceof MainLogger) { $this->logger->logException($e); } } } $this->getNetwork()->updateName(); } if ($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks) { $this->autoSaveTicker = 0; $this->doAutoSave(); } if ($this->sendUsageTicker > 0 and --$this->sendUsageTicker === 0) { $this->sendUsageTicker = 6000; $this->sendUsage(SendUsageTask::TYPE_STATUS); } if ($this->tickCounter % 100 === 0) { foreach ($this->levels as $level) { $level->clearCache(); } if ($this->getTicksPerSecondAverage() < 12) { $this->logger->warning($this->getLanguage()->translateString("pocketmine.server.tickOverload")); } } if ($this->dispatchSignals and $this->tickCounter % 5 === 0) { pcntl_signal_dispatch(); } $this->getMemoryManager()->check(); Timings::$serverTickTimer->stopTiming(); $now = microtime(true); $tick = min(20, 1 / max(0.001, $now - $tickTime)); $use = min(1, ($now - $tickTime) / 0.05); TimingsHandler::tick($tick <= $this->profilingTickRate); if ($this->maxTick > $tick) { $this->maxTick = $tick; } if ($this->maxUse < $use) { $this->maxUse = $use; } array_shift($this->tickAverage); $this->tickAverage[] = $tick; array_shift($this->useAverage); $this->useAverage[] = $use; if ($this->nextTick - $tickTime < -1) { $this->nextTick = $tickTime; } else { $this->nextTick += 0.05; } return true; }
/** * Tries to execute a server tick */ private function tick() { $tickTime = microtime(true); if ($tickTime < $this->nextTick) { return false; } Timings::$serverTickTimer->startTiming(); ++$this->tickCounter; $this->checkConsole(); Timings::$connectionTimer->startTiming(); $this->network->processInterfaces(); Timings::$connectionTimer->stopTiming(); Timings::$schedulerTimer->startTiming(); $this->scheduler->mainThreadHeartbeat($this->tickCounter); Timings::$schedulerTimer->stopTiming(); $this->checkTickUpdates($this->tickCounter); if (($this->tickCounter & 0b1111) === 0) { $this->titleTick(); if ($this->queryHandler !== null and ($this->tickCounter & 0b111111111) === 0) { try { $this->queryHandler->regenerateInfo(); } catch (\Exception $e) { if ($this->logger instanceof MainLogger) { $this->logger->logException($e); } } } } Timings::$generationTimer->startTiming(); try { $this->generationManager->process(); } catch (\Exception $e) { if ($this->logger instanceof MainLogger) { $this->logger->logException($e); } } Timings::$generationTimer->stopTiming(); if ($this->tickCounter % 100 === 0) { foreach ($this->levels as $level) { $level->clearCache(); } } Timings::$serverTickTimer->stopTiming(); TimingsHandler::tick(); $now = microtime(true); array_shift($this->tickAverage); $this->tickAverage[] = min(20, 1 / max(0.001, $now - $tickTime)); array_shift($this->useAverage); $this->useAverage[] = min(1, ($now - $tickTime) / 0.05); if ($this->nextTick - $tickTime < -1) { $this->nextTick = $tickTime; } $this->nextTick += 0.05; return true; }
public function execute(ServerScheduler $scheduler, Position $anchor, WorldEditArt $main) { $ticks = 0; foreach ($this->ops as $op) { if ($op->getType() === MacroOperation::TYPE_WAIT) { $ticks += $op->getLength(); continue; } $scheduler->scheduleDelayedTask(new MacroOperationTask($main, $op, $anchor), $ticks); } }