本文整理汇总了PHP中pocketmine\Server::getScheduler方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::getScheduler方法的具体用法?PHP Server::getScheduler怎么用?PHP Server::getScheduler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Server
的用法示例。
在下文中一共展示了Server::getScheduler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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: __construct
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: doUpgrade
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: disablePlugin
/**
* @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: triggerGarbageCollector
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: onCompletion
/**
* @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: disablePlugin
/**
* @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: collectTasks
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: processChunkRequest
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: generateChunk
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: processChunkRequest
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: generateChunk
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: processChunkRequest
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: addLightning
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: generateChunk
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();
}
}