Beispiel #1
0
 /**
  * WARNING: Do not use this, it's only for internal use.
  * Changes to this function won't be recorded on the version.
  *
  * @param int $currentTick
  *
  * @return bool
  */
 public function doTick(int $currentTick)
 {
     $this->timings->doTick->startTiming();
     $this->checkTime();
     if (++$this->sendTimeTicker === 280) {
         $this->sendTime();
         $this->sendTimeTicker = 0;
     }
     $this->weather->calcWeather($currentTick);
     $this->unloadChunks();
     //Do block updates
     $this->timings->doTickPending->startTiming();
     if ($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick) {
         $block = $this->getBlock($this->updateQueue->extract()["data"]);
         unset($this->updateQueueIndex[Level::blockHash($block->x, $block->y, $block->z)]);
         $block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
     }
     $this->timings->doTickPending->stopTiming();
     $this->timings->entityTick->startTiming();
     //Update entities that need update
     Timings::$tickEntityTimer->startTiming();
     foreach ($this->updateEntities as $id => $entity) {
         if ($entity->closed or !$entity->onUpdate($currentTick)) {
             unset($this->updateEntities[$id]);
         }
     }
     Timings::$tickEntityTimer->stopTiming();
     $this->timings->entityTick->stopTiming();
     $this->timings->tileEntityTick->startTiming();
     Timings::$tickTileEntityTimer->startTiming();
     //Update tiles that need update
     if (count($this->updateTiles) > 0) {
         foreach ($this->updateTiles as $id => $tile) {
             if ($tile->onUpdate() !== true) {
                 unset($this->updateTiles[$id]);
             }
         }
     }
     Timings::$tickTileEntityTimer->stopTiming();
     $this->timings->tileEntityTick->stopTiming();
     $this->timings->doTickTiles->startTiming();
     if ($currentTick % 2 === 0) {
         $this->tickChunks();
     }
     $this->timings->doTickTiles->stopTiming();
     if (count($this->changedBlocks) > 0) {
         if (count($this->players) > 0) {
             foreach ($this->changedBlocks as $index => $blocks) {
                 unset($this->chunkCache[$index]);
                 Level::getXZ($index, $chunkX, $chunkZ);
                 if (count($blocks) > 512) {
                     $chunk = $this->getChunk($chunkX, $chunkZ);
                     foreach ($this->getChunkPlayers($chunkX, $chunkZ) as $p) {
                         $p->onChunkChanged($chunk);
                     }
                 } else {
                     $this->sendBlocks($this->getChunkPlayers($chunkX, $chunkZ), $blocks, UpdateBlockPacket::FLAG_ALL);
                 }
             }
         } else {
             $this->chunkCache = [];
         }
         $this->changedBlocks = [];
     }
     $this->processChunkRequest();
     if ($this->sleepTicks > 0 and --$this->sleepTicks <= 0) {
         $this->checkSleep();
     }
     foreach ($this->moveToSend as $index => $entry) {
         Level::getXZ($index, $chunkX, $chunkZ);
         foreach ($entry as $e) {
             $this->addChunkPacket($chunkX, $chunkZ, $e);
         }
     }
     $this->moveToSend = [];
     foreach ($this->motionToSend as $index => $entry) {
         Level::getXZ($index, $chunkX, $chunkZ);
         foreach ($entry as $entity) {
             $pk = new SetEntityMotionPacket();
             $pk->eid = $entity[0];
             $pk->motionX = $entity[1];
             $pk->motionY = $entity[2];
             $pk->motionZ = $entity[3];
             $this->addChunkPacket($chunkX, $chunkZ, $pk);
         }
     }
     $this->motionToSend = [];
     foreach ($this->chunkPackets as $index => $entries) {
         Level::getXZ($index, $chunkX, $chunkZ);
         $chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ);
         if (count($chunkPlayers) > 0) {
             foreach ($entries as $pk) {
                 Server::broadcastPacket($chunkPlayers, $pk);
             }
         }
     }
     $this->chunkPackets = [];
     $this->timings->doTick->stopTiming();
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) < 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if ($sender instanceof Player) {
         $wea = Weather::getWeatherFromString($args[0]);
         if (!isset($args[1])) {
             $duration = mt_rand(min($sender->getServer()->weatherRandomDurationMin, $sender->getServer()->weatherRandomDurationMax), max($sender->getServer()->weatherRandomDurationMin, $sender->getServer()->weatherRandomDurationMax));
         } else {
             $duration = (int) $args[1];
         }
         if ($wea >= 0 and $wea <= 3) {
             $sender->getLevel()->getWeather()->setWeather($wea, $duration);
             $sender->sendMessage(new TranslationContainer("pocketmine.command.weather.changed", [$sender->getLevel()->getFolderName()]));
             return true;
             /*if(WeatherManager::isRegistered($sender->getLevel())){
             			$sender->getLevel()->getWeather()->setWeather($wea, $duration);
             			$sender->sendMessage(new TranslationContainer("pocketmine.command.weather.changed", [$sender->getLevel()->getFolderName()]));
             			return true;
             		}else{
             			$sender->sendMessage(new TranslationContainer("pocketmine.command.weather.noregistered", [$sender->getLevel()->getFolderName()]));
             			return false;
             		}*/
         } else {
             $sender->sendMessage(TextFormat::RED . "%pocketmine.command.weather.invalid");
             return false;
         }
     }
     if (count($args) < 2) {
         $sender->sendMessage(TextFormat::RED . "%pocketmine.command.weather.wrong");
         return false;
     }
     $level = $sender->getServer()->getLevelByName($args[0]);
     if (!$level instanceof Level) {
         $sender->sendMessage(TextFormat::RED . "%pocketmine.command.weather.invalid.level");
         return false;
     }
     $wea = Weather::getWeatherFromString($args[1]);
     if (!isset($args[1])) {
         $duration = mt_rand(min($sender->getServer()->weatherRandomDurationMin, $sender->getServer()->weatherRandomDurationMax), max($sender->getServer()->weatherRandomDurationMin, $sender->getServer()->weatherRandomDurationMax));
     } else {
         $duration = (int) $args[1];
     }
     if ($wea >= 0 and $wea <= 3) {
         $level->getWeather()->setWeather($wea, $duration);
         $sender->sendMessage(new TranslationContainer("pocketmine.command.weather.changed", [$level->getFolderName()]));
         return true;
         /*if(WeatherManager::isRegistered($level)){
         			$level->getWeather()->setWeather($wea, $duration);
         			$sender->sendMessage(new TranslationContainer("pocketmine.command.weather.changed", [$level->getFolderName()]));
         			return true;
         		}else{
         			$sender->sendMessage(new TranslationContainer("pocketmine.command.weather.noregistered", [$level->getFolderName()]));
         			return false;
         		}*/
     } else {
         $sender->sendMessage(TextFormat::RED . "%pocketmine.command.weather.invalid");
         return false;
     }
 }