public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); $chunk = $this->level->getChunk($chunkX, $chunkZ); for ($x = 0; $x < 16; ++$x) { for ($z = 0; $z < 16; ++$z) { $biome = Biome::getBiome(Biome::HELL); $chunk->setBiomeId($x, $z, $biome->getId()); $color = [0, 0, 0]; $bColor = $biome->getColor(); $color[0] += ($bColor >> 16) ** 2; $color[1] += ($bColor >> 8 & 0xff) ** 2; $color[2] += ($bColor & 0xff) ** 2; $chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]); for ($y = 0; $y < 128; ++$y) { if ($y === 0 or $y === 127) { $chunk->setBlockId($x, $y, $z, Block::BEDROCK); continue; } $noiseValue = abs($this->emptyHeight - $y) / $this->emptyHeight * $this->emptyAmplitude - $noise[$x][$z][$y]; $noiseValue -= 1 - $this->density; if ($noiseValue > 0) { $chunk->setBlockId($x, $y, $z, Block::NETHERRACK); } elseif ($y <= $this->waterHeight) { $chunk->setBlockId($x, $y, $z, Block::STILL_LAVA); } } } } foreach ($this->generationPopulators as $populator) { $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } }
public function onLoad() { Generator::addGenerator(NoneGN::class, "None"); Generator::addGenerator(OreFlatGN::class, "OreFlat"); Generator::addGenerator(SkyBlockGN::class, "SkyBlock"); Generator::addGenerator(SkyGridGN::class, "SkyGrid"); }
public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if (strtolower($command->getName()) === "buyworld") { if (count($args) < 1 || count($args) > 4) { return false; } if (EconomyAPI::getInstance()->myMoney($sender->getName()) < 10000) { $sender->sendMessage(TextFormat::RED . "[HyperPlot] You don't have enought money. It cost \$10000"); return true; } $world = array_shift($args); if (strlen($world) < 3) { $sender->sendMessage(TextFormat::RED . "[HyperPlot] Small World name"); return true; } if ($this->getServer()->isLevelGenerated($world)) { $sender->sendMessage(TextFormat::RED . "[HyperPlot] A world named " . $world . " already exists"); return true; } EconomyAPI::getInstance()->reduceMoney($sender->getName(), 10000); $this->getServer()->broadcastMessage($sender->sendMessage(TextFormat::RED . "[HyperPlot] Creating level " . $sender->getName() . "-" . $world . "...")); $generator = Generator::getGenerator("ownworld"); $this->getServer()->generateLevel($sender->getName() . "-" . $world, null, $generator, []); $this->getServer()->loadLevel($sender->getName() . "-" . $world); return true; } return false; }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args) { if (count($args) < 1 || count($args) > 4) { return false; } $world = array_shift($args); if ($this->owner->getServer()->isLevelGenerated($world)) { $c->sendMessage(TextFormat::RED . mc::_("[MW] A world named %1% already exists", $world)); return true; } $seed = null; $generator = null; $opts = []; if (isset($args[0])) { $seed = intval($args[0]); } if (isset($args[1])) { $generator = Generator::getGenerator($args[1]); if (strtolower($args[1]) != Generator::getGeneratorName($generator)) { $c->sendMessage(TextFormat::RED . mc::_("[MW] Unknown generator %1%", $args[1])); return true; } $c->sendMessage(TextFormat::GREEN . mc::_("[MW] Using %1%", Generator::getGeneratorName($generator))); } if (isset($args[2])) { $opts = ["preset" => $args[2]]; } $this->owner->getServer()->broadcastMessage(mc::_("[MW] Creating level %1%... (Expect Lag)", $world)); $this->owner->getServer()->generateLevel($world, $seed, $generator, $opts); $this->owner->getServer()->loadLevel($world); return true; }
public function onEnable() { $api = $this->getServer()->getApiVersion(); if (version_compare($api, "1.12.0") >= 0) { $this->getLogger()->info(TextFormat::RED . "WARNING: PMv1.5 support is experimental!"); Generator::addGenerator(NotSoFlat::class, "notsoflat"); } else { Generator::addGenerator(NotSoFlatOld::class, "notsoflat"); } }
public static function generate($path, $name, $seed, $generator, array $options = []) { @mkdir($path, 0777, true); @mkdir($path . "/region", 0777); //TODO, add extra details $levelData = new Compound("Data", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]); $nbt = new NBT(NBT::BIG_ENDIAN); $nbt->setData(new Compound(null, ["Data" => $levelData])); $buffer = $nbt->writeCompressed(); @file_put_contents($path . "level.dat", $buffer); }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args) { if (count($args) != 0) { return false; } if (MPMU::apiVersion("1.12.0")) { $c->sendMessage(implode(", ", Generator::getGeneratorList())); } else { $c->sendMessage("normal, flat"); $c->sendMessage(TextFormat::RED . mc::_("[MW] Plugin provided world generators\n are not included in\n this list.")); } return true; }
public function populateChunk($chunkX, $chunkZ) { if (!$this->isChunkGenerated($chunkX, $chunkZ)) { $this->generateChunk($chunkX, $chunkZ); } for ($z = $chunkZ - 1; $z <= $chunkZ + 1; ++$z) { for ($x = $chunkX - 1; $x <= $chunkX + 1; ++$x) { if (!$this->isChunkGenerated($x, $z)) { $this->generateChunk($x, $z); } } } $this->generator->populateChunk($chunkX, $chunkZ); $this->setChunkPopulated($chunkX, $chunkZ); }
public static function generate($path, $name, $seed, $generator, array $options = []) { if (!file_exists($path)) { mkdir($path, 0777, true); } if (!file_exists($path . "/db")) { mkdir($path . "/db", 0777, true); } //TODO, add extra details $levelData = new Compound("", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "RainTime" => new Int("RainTime", 0), "Raining" => new String("Raining", false), "ThunderTime" => new Int("ThunderTime", 0), "Thundering" => new String("Thundering", false), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]); $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($levelData); $buffer = $nbt->write(); file_put_contents($path . "level.dat", Binary::writeLInt(3) . Binary::writeLInt(strlen($buffer)) . $buffer); $db = new \LevelDB($path . "/db"); $db->close(); }
public function onEnable() { Generator::addGenerator(ApartGN::class, "Apart"); Generator::addGenerator(Ice::class, "Ice"); Generator::addGenerator(Lava::class, "Lava"); Generator::addGenerator(ManySkyBlockGN::class, "ManySkyBlock"); Generator::addGenerator(ManyTreeGN::class, "ManyTree"); Generator::addGenerator(MultySkyBlockGN::class, "MultySkyBlock"); Generator::addGenerator(MultySpecialSkyBlockGN::class, "MultySpecialSkyBlock"); Generator::addGenerator(NoneGN::class, "None"); Generator::addGenerator(OreFlatGN::class, "OreFlat"); Generator::addGenerator(OreTreeFlatGN::class, "OreTreeFlat"); Generator::addGenerator(SkyBlockGN::class, "SkyBlock"); Generator::addGenerator(SkyGridGN::class, "SkyGrid"); Generator::addGenerator(TreeGN::class, "Tree"); Generator::addGenerator(WaterGN::class, "Water"); Generator::addGenerator(WhiteWayGN::class, "WhiteWay"); }
public function __construct(Level $level, $path) { $this->level = $level; $this->path = $path; if (!file_exists($this->path)) { mkdir($this->path, 0777, true); } $nbt = new NBT(NBT::BIG_ENDIAN); $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat")); $levelData = $nbt->getData(); if ($levelData->Data instanceof Compound) { $this->levelData = $levelData->Data; } else { throw new LevelException("Invalid level.dat"); } if (!isset($this->levelData->generatorName)) { $this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT")); } if (!isset($this->levelData->generatorOptions)) { $this->levelData->generatorOptions = new String("generatorOptions", ""); } }
/** * Init the default level data * * @param Server $server * @param string $name * @param string $path * @param string $provider Class that extends LevelProvider * * @throws \Exception */ public function __construct(Server $server, $name, $path, $provider) { $this->blockStates = Block::$fullList; $this->levelId = static::$levelIdCounter++; $this->blockMetadata = new BlockMetadataStore($this); $this->server = $server; $this->autoSave = $server->getAutoSave(); /** @var LevelProvider $provider */ if (is_subclass_of($provider, LevelProvider::class, true)) { $this->provider = new $provider($this, $path); } else { throw new LevelException("Provider is not a subclass of LevelProvider"); } $this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\""); $this->generator = Generator::getGenerator($this->provider->getGenerator()); $this->blockOrder = $provider::getProviderOrder(); $this->useSections = $provider::usesChunkSection(); $this->folderName = $name; $this->updateQueue = new ReversePriorityQueue(); $this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); $this->time = (int) $this->provider->getTime(); $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 0); $this->chunkTickList = []; $this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", false); $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); $this->temporalVector = new Vector3(0, 0, 0); }
public function onEnable() { self::$instance = $this; $folder = $this->getDataFolder(); if (!is_dir($folder)) { mkdir($folder); } if (!is_dir($folder . "worlds")) { mkdir($folder . "worlds"); } Generator::addGenerator(MyPlotGenerator::class, "myplot"); $this->saveDefaultConfig(); $this->reloadConfig(); $this->getLogger()->info(TextFormat::GREEN . "Loading the Plot Framework!"); $this->getLogger()->warning(TextFormat::YELLOW . "It seems that you are running the development build of MyPlot! Thats cool, but it CAN be very, very buggy! Just be careful when using this plugin and report any issues to" . TextFormat::GOLD . " http://github.com/wiez/MyPlot/issues"); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); $this->getServer()->getCommandMap()->register(Commands::class, new Commands($this)); switch (strtolower($this->getConfig()->get("DataProvider"))) { case "sqlite": default: $this->dataProvider = new SQLiteDataProvider($this); break; } if ($this->getConfig()->get("UseEconomy") == true) { if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) { $this->economyProvider = new EconomySProvider(); } elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) { $this->economyProvider = new PocketMoneyProvider($plugin); } else { $this->economyProvider = null; } } else { $this->economyProvider = null; } }
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0.0 ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); $chunk = $this->level->getChunk($chunkX, $chunkZ); $biomeCache = []; for ($x = 0; $x < 16; ++$x) { for ($z = 0; $z < 16; ++$z) { $minSum = 0; $maxSum = 0; $weightSum = 0; $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z); $chunk->setBiomeId($x, $z, $biome->getId()); $color = [0, 0, 0]; for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) { for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) { $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE]; if ($sx === 0 and $sz === 0) { $adjacent = $biome; } else { $index = ($chunkX * 16 + $x + $sx & 4294967295.0) << 32 | $chunkZ * 16 + $z + $sz & 4294967295.0; if (isset($biomeCache[$index])) { $adjacent = $biomeCache[$index]; } else { $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); } } $minSum += ($adjacent->getMinElevation() - 1) * $weight; $maxSum += $adjacent->getMaxElevation() * $weight; $bColor = $adjacent->getColor(); $color[0] += ($bColor >> 16) ** 2 * $weight; $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight; $color[2] += ($bColor & 0xff) ** 2 * $weight; $weightSum += $weight; } } $minSum /= $weightSum; $maxSum /= $weightSum; $chunk->setBiomeColor($x, $z, \sqrt($color[0] / $weightSum), \sqrt($color[1] / $weightSum), \sqrt($color[2] / $weightSum)); $smoothHeight = ($maxSum - $minSum) / 2; for ($y = 0; $y < 128; ++$y) { if ($y === 0) { $chunk->setBlockId($x, $y, $z, Block::BEDROCK); continue; } $noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum); if ($noiseValue > 0) { $chunk->setBlockId($x, $y, $z, Block::STONE); } elseif ($y <= $this->waterHeight) { $chunk->setBlockId($x, $y, $z, Block::STILL_WATER); } } } } foreach ($this->generationPopulators as $populator) { $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } }
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $seaFloorNoise = Generator::getFastNoise2D($this->noiseSeaFloor, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16); $landNoise = Generator::getFastNoise2D($this->noiseLand, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16); $mountainNoise = Generator::getFastNoise2D($this->noiseMountains, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16); $baseNoise = Generator::getFastNoise2D($this->noiseBaseGround, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16); $riverNoise = Generator::getFastNoise2D($this->noiseRiver, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16); $chunk = $this->level->getChunk($chunkX, $chunkZ); for ($genx = 0; $genx < 16; $genx++) { for ($genz = 0; $genz < 16; $genz++) { $canBaseGround = false; $canRiver = true; //using a quadratic function which smooth the world //y = (2.956x)^2 - 0.6, (0 <= x <= 2) $landHeightNoise = $landNoise[$genx][$genz] + 1; $landHeightNoise *= 2.956; $landHeightNoise = $landHeightNoise * $landHeightNoise; $landHeightNoise = $landHeightNoise - 0.6; $landHeightNoise = $landHeightNoise > 0 ? $landHeightNoise : 0; //generate mountains $mountainHeightGenerate = $mountainNoise[$genx][$genz] - 0.2; $mountainHeightGenerate = $mountainHeightGenerate > 0 ? $mountainHeightGenerate : 0; $mountainGenerate = (int) ($this->mountainHeight * $mountainHeightGenerate); $landHeightGenerate = (int) ($this->landHeightRange * $landHeightNoise); if ($landHeightGenerate > $this->landHeightRange) { if ($landHeightGenerate > $this->landHeightRange) { $canBaseGround = true; } $landHeightGenerate = $this->landHeightRange; } $genyHeight = $this->seaFloorHeight + $landHeightGenerate; $genyHeight += $mountainGenerate; //prepare for generate ocean, desert, and land if ($genyHeight < $this->beathStartHeight) { if ($genyHeight < $this->beathStartHeight - 5) { $genyHeight += (int) ($this->seaFloorGenerateRange * $seaFloorNoise[$genx][$genz]); } $biome = Biome::getBiome(Biome::OCEAN); if ($genyHeight < $this->seaFloorHeight - $this->seaFloorGenerateRange) { $genyHeight = $this->seaFloorHeight; } $canRiver = false; } else { if ($genyHeight <= $this->beathStopHeight && $genyHeight >= $this->beathStartHeight) { //todo: there is no beach biome, use desert temporarily $biome = Biome::getBiome(Biome::DESERT); } else { $biome = $this->pickBiome($chunkX * 16 + $genx, $chunkZ * 16 + $genz); if ($canBaseGround) { $baseGroundHeight = (int) ($this->landHeightRange * $landHeightNoise) - $this->landHeightRange; $baseGroundHeight2 = (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1)); if ($baseGroundHeight2 > $baseGroundHeight) { $baseGroundHeight2 = $baseGroundHeight; } if ($baseGroundHeight2 > $mountainGenerate) { $baseGroundHeight2 = $baseGroundHeight2 - $mountainGenerate; } else { $baseGroundHeight2 = 0; } $genyHeight += $baseGroundHeight2; } } } if ($canRiver && $genyHeight <= $this->seaHeight - 5) { $canRiver = false; } //generate river if ($canRiver) { $riverGenerate = $riverNoise[$genx][$genz]; if ($riverGenerate > -0.25 && $riverGenerate < 0.25) { $riverGenerate = $riverGenerate > 0 ? $riverGenerate : -$riverGenerate; $riverGenerate = 0.25 - $riverGenerate; //y=x^2 * 4 - 0.0000001 $riverGenerate = $riverGenerate * $riverGenerate * 4; //smooth again $riverGenerate = $riverGenerate - 1.0E-7; $riverGenerate = $riverGenerate > 0 ? $riverGenerate : 0; $genyHeight -= $riverGenerate * 64; if ($genyHeight < $this->seaHeight) { $biome = Biome::getBiome(Biome::RIVER); //to generate river floor if ($genyHeight <= $this->seaHeight - 8) { $genyHeight1 = $this->seaHeight - 9 + (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1)); $genyHeight2 = $genyHeight < $this->seaHeight - 7 ? $this->seaHeight - 7 : $genyHeight; $genyHeight = $genyHeight1 > $genyHeight2 ? $genyHeight1 : $genyHeight2; } } } } $chunk->setBiomeId($genx, $genz, $biome->getId()); //biome color //todo: smooth chunk color $biomeColor = $biome->getColor(); $chunk->setBiomeColor($genx, $genz, $biomeColor >> 16, $biomeColor >> 8 & 0xff, $biomeColor & 0xff); //generating $generateHeight = $genyHeight > $this->seaHeight ? $genyHeight : $this->seaHeight; for ($geny = 0; $geny <= $generateHeight; $geny++) { if ($geny <= $this->bedrockDepth && ($geny == 0 or $this->random->nextRange(1, 5) == 1)) { $chunk->setBlockId($genx, $geny, $genz, Block::BEDROCK); } elseif ($geny > $genyHeight) { if (($biome->getId() == Biome::ICE_PLAINS or $biome->getId() == Biome::TAIGA) and $geny == $this->seaHeight) { $chunk->setBlockId($genx, $geny, $genz, Block::ICE); } else { $chunk->setBlockId($genx, $geny, $genz, Block::STILL_WATER); } } else { $chunk->setBlockId($genx, $geny, $genz, Block::STONE); } } } } //populator chunk foreach ($this->generationPopulators as $populator) { $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } }
public function getWaterHeight() : int { if ($this->generatorInstance instanceof Generator) { return $this->generatorInstance->getWaterHeight(); } return 0; }
/** * Init the default level data * * @param Server $server * @param string $name * @param string $path * @param string $provider Class that extends LevelProvider * * @throws \Exception */ public function __construct(Server $server, $name, $path, $provider) { $this->levelId = static::$levelIdCounter++; $this->blockMetadata = new BlockMetadataStore($this); $this->server = $server; /** @var LevelProvider $provider */ if (is_subclass_of($provider, "pocketmine\\level\\format\\LevelProvider", true)) { $this->provider = new $provider($this, $path); } else { throw new \Exception("Provider is not a subclass of LevelProvider"); } $this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\""); $generator = Generator::getGenerator($this->provider->getGenerator()); $this->server->getGenerationManager()->openLevel($this, $generator, $this->provider->getGeneratorOptions()); $this->blockOrder = $provider::getProviderOrder(); $this->useSections = $provider::usesChunkSection(); $this->folderName = $name; $this->updateQueue = new ReversePriorityQueue(); $this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); $this->time = (int) $this->provider->getTime(); $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 3))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 80); $this->chunkTickList = []; $this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", false); $this->timings = new LevelTimings($this); }
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); $chunk = $this->level->getChunk($chunkX, $chunkZ); $biomeCache = []; for ($x = 0; $x < 16; ++$x) { for ($z = 0; $z < 16; ++$z) { $minSum = 0; $maxSum = 0; $weightSum = 0; $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z); $chunk->setBiomeId($x, $z, $biome->getId()); $color = [0, 0, 0]; for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) { for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) { $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE]; if ($sx === 0 and $sz === 0) { $adjacent = $biome; } else { $index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); if (isset($biomeCache[$index])) { $adjacent = $biomeCache[$index]; } else { $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); } } $minSum += ($adjacent->getMinElevation() - 1) * $weight; $maxSum += $adjacent->getMaxElevation() * $weight; $bColor = $adjacent->getColor(); $color[0] += ($bColor >> 16) ** 2 * $weight; $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight; $color[2] += ($bColor & 0xff) ** 2 * $weight; $weightSum += $weight; } } $minSum /= $weightSum; $maxSum /= $weightSum; $chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum)); $solidLand = false; for ($y = 127; $y >= 0; --$y) { if ($y === 0) { $chunk->setBlockId($x, $y, $z, Block::BEDROCK); continue; } // A noiseAdjustment of 1 will guarantee ground, a noiseAdjustment of -1 will guarantee air. //$effHeight = min($y - $smoothHeight - $minSum, $noiseAdjustment = 2 * (($maxSum - $y) / ($maxSum - $minSum)) - 1; // To generate caves, we bring the noiseAdjustment down away from 1. $caveLevel = $minSum - 10; $distAboveCaveLevel = max(0, $y - $caveLevel); // must be positive $noiseAdjustment = min($noiseAdjustment, 0.4 + $distAboveCaveLevel / 10); $noiseValue = $noise[$x][$z][$y] + $noiseAdjustment; if ($noiseValue > 0) { $chunk->setBlockId($x, $y, $z, Block::STONE); $solidLand = true; } elseif ($y <= $this->waterHeight && $solidLand == false) { $chunk->setBlockId($x, $y, $z, Block::STILL_WATER); } } } } foreach ($this->generationPopulators as $populator) { $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } }
public function onEnable() { $this->getLogger()->info("Loading MyPlot"); self::$instance = $this; $this->saveDefaultConfig(); $this->reloadConfig(); @mkdir($this->getDataFolder()); @mkdir($this->getDataFolder() . "worlds"); Generator::addGenerator(MyPlotGenerator::class, "myplot"); $lang = $this->getConfig()->get("language", BaseLang::FALLBACK_LANGUAGE); $this->baseLang = new BaseLang($lang, $this->getFile() . "resources/"); // Initialize DataProvider $cacheSize = $this->getConfig()->get("PlotCacheSize"); switch (strtolower($this->getConfig()->get("DataProvider"))) { case "sqlite": default: $this->dataProvider = new SQLiteDataProvider($this, $cacheSize); break; } // Initialize EconomyProvider if ($this->getConfig()->get("UseEconomy") == true) { if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) { $this->economyProvider = new EconomySProvider(); } elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) { $this->economyProvider = new PocketMoneyProvider($plugin); } } $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); $this->getServer()->getCommandMap()->register(Commands::class, new Commands($this)); }
/** * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath) { self::$instance = $this; self::$sleeper = new \Threaded(); $this->autoloader = $autoloader; $this->logger = $logger; $this->filePath = $filePath; try { if (!file_exists($dataPath . "worlds/")) { mkdir($dataPath . "worlds/", 0777); } if (!file_exists($dataPath . "players/")) { mkdir($dataPath . "players/", 0777); } if (!file_exists($pluginPath)) { mkdir($pluginPath, 0777); } if (!file_exists($dataPath . "crashdumps/")) { mkdir($dataPath . "crashdumps/", 0777); } $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->console = new CommandReader(); $version = new VersionString($this->getPocketMineVersion()); $this->version = $version; $this->aboutstring = "\n\n\t\t §5PocketMine-iTX §3Genisys §fis a fork of PocketMine-MP.\n\t\t Powered by §5iTX Technologies LLC.\n\t\t §fVersion: §6" . $this->getPocketMineVersion() . "\n\t\t §fClient Version: §d0.13.1 alpha\n\t\t §fYou could get the lastest code on https://github.com/iTXTech/Genisys\n\t\t §fDonate link: http://pl.zxda.net/plugins/203.html\n\t\t §f如果你在免费使用本核心,希望你可以进入上面的链接捐赠给我们,这会成为我们前进的动力。\n\t\t\n"; $this->about(); $this->logger->info("Loading pocketmine.yml..."); if (!file_exists($this->dataPath . "pocketmine.yml")) { $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); if ($version->isDev()) { $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content); } @file_put_contents($this->dataPath . "pocketmine.yml", $content); } $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $this->logger->info("Loading genisys.yml..."); $lang = $this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE); if (file_exists($this->filePath . "src/pocketmine/resources/genisys_{$lang}.yml")) { $content = file_get_contents($file = $this->filePath . "src/pocketmine/resources/genisys_{$lang}.yml"); } else { $content = file_get_contents($file = $this->filePath . "src/pocketmine/resources/genisys_eng.yml"); } if (!file_exists($this->dataPath . "genisys.yml")) { @file_put_contents($this->dataPath . "genisys.yml", $content); } $internelConfig = new Config($file, Config::YAML, []); $this->advancedConfig = new Config($this->dataPath . "genisys.yml", Config::YAML, []); $cfgVer = $this->getAdvancedProperty("config.version", 0, $internelConfig); $advVer = $this->getAdvancedProperty("config.version", 0); $this->loadAdvancedConfig(); if ($this->expWriteAhead > 0) { $this->generateExpCache($this->expWriteAhead); } $this->logger->info("Loading server properties..."); $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true]); $this->forceLanguage = $this->getProperty("settings.force-language", false); $this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE)); $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()])); $this->memoryManager = new MemoryManager($this); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getVersion()])); if (($poolSize = $this->getProperty("settings.async-workers", "auto")) === "auto") { $poolSize = ServerScheduler::$WORKERS; $processors = Utils::getCoreCount() - 2; if ($processors > 0) { $poolSize = max(1, $processors); } } ServerScheduler::$WORKERS = $poolSize; if ($this->getProperty("network.batch-threshold", 256) >= 0) { Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); } else { Network::$BATCH_THRESHOLD = -1; } $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); $this->networkCompressionAsync = $this->getProperty("network.async-compression", true); $this->autoTickRate = (bool) $this->getProperty("level-settings.auto-tick-rate", true); $this->autoTickRateLimit = (int) $this->getProperty("level-settings.auto-tick-rate-limit", 20); $this->alwaysTickPlayers = (int) $this->getProperty("level-settings.always-tick-players", false); $this->baseTickRate = (int) $this->getProperty("level-settings.base-tick-rate", 1); $this->scheduler = new ServerScheduler(); if ($this->getConfigBoolean("enable-rcon", false) === true) { $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); $this->levelMetadata = new LevelMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) { @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt"); } @touch($this->dataPath . "banned-players.txt"); $this->banByName = new BanList($this->dataPath . "banned-players.txt"); $this->banByName->load(); @touch($this->dataPath . "banned-ips.txt"); $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); @touch($this->dataPath . "banned-cids.txt"); $this->banByCID = new BanList($this->dataPath . "banned-cids.txt"); $this->banByCID->load(); $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) { $this->setConfigInt("difficulty", 3); } define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1)); if ($this->logger instanceof MainLogger) { $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } if (\pocketmine\DEBUG >= 0) { @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); } $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()])); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId()); $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId()); $this->network = new Network($this); $this->network->setName($this->getMotd()); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), $this->getPocketMineVersion(), $this->getCodename(), $this->getApiVersion()])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()])); Timings::init(); $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); $this->registerEntities(); $this->registerTiles(); InventoryType::init(min(32, $this->inventoryNum)); //Bigger than 32 with cause problems Block::init(); Item::init(); Biome::init(); Effect::init(); Enchantment::init(); Attribute::init(); /** TODO: @deprecated */ //TextWrapper::init(); $this->craftingManager = new CraftingManager($this->readRecipesFromJson); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); $this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20); $this->pluginManager->registerInterface(PharPluginLoader::class); $this->pluginManager->registerInterface(FolderPluginLoader::class); $this->pluginManager->registerInterface(ScriptPluginLoader::class); //set_exception_handler([$this, "exceptionHandler"]); register_shutdown_function([$this, "crashDump"]); $this->queryRegenerateTask = new QueryRegenerateEvent($this, 5); $this->network->registerInterface(new RakLibInterface($this)); $this->pluginManager->loadPlugins($this->pluginPath); //$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net")); $this->enablePlugins(PluginLoadOrder::STARTUP); LevelProviderManager::addProvider($this, Anvil::class); LevelProviderManager::addProvider($this, McRegion::class); if (extension_loaded("leveldb")) { $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable")); LevelProviderManager::addProvider($this, LevelDB::class); } Generator::addGenerator(Flat::class, "flat"); Generator::addGenerator(Normal::class, "normal"); Generator::addGenerator(Normal::class, "default"); Generator::addGenerator(Nether::class, "hell"); Generator::addGenerator(Nether::class, "nether"); foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) { if ($this->loadLevel($name) === false) { $seed = $this->getProperty("worlds.{$name}.seed", time()); $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default"))); $generator = Generator::getGenerator(array_shift($options)); if (count($options) > 0) { $options = ["preset" => implode(":", $options)]; } else { $options = []; } $this->generateLevel($name, $seed, $generator, $options); } } if ($this->getDefaultLevel() === null) { $default = $this->getConfigString("level-name", "world"); if (trim($default) == "") { $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } if ($this->loadLevel($default) === false) { $seed = $this->getConfigInt("level-seed", time()); $this->generateLevel($default, $seed === 0 ? time() : $seed); } $this->setDefaultLevel($this->getLevelByName($default)); } $this->properties->save(true); if (!$this->getDefaultLevel() instanceof Level) { $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError")); $this->forceShutdown(); return; } if ($this->netherEnabled) { if (!$this->loadLevel($this->netherName)) { //$this->logger->info("正在生成地狱 ".$this->netherName); $this->generateLevel($this->netherName, time(), Generator::getGenerator("nether")); } $this->netherLevel = $this->getLevelByName($this->netherName); } if ($this->getProperty("ticks-per.autosave", 6000) > 0) { $this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000); } $this->enablePlugins(PluginLoadOrder::POSTWORLD); if ($this->aiEnabled) { $this->aiHolder = new AIHolder($this); } if ($this->dserverConfig["enable"] and $this->getAdvancedProperty("dserver.server-list", "") != "") { $this->scheduler->scheduleRepeatingTask(new CallbackTask([$this, "updateDServerInfo"]), $this->dserverConfig["timer"]); } if ($cfgVer != $advVer) { $this->logger->notice("Your genisys.yml needs update"); $this->logger->notice("Current Version: {$advVer} Latest Version: {$cfgVer}"); } $this->generateRecipeList(); $this->start(); } catch (\Throwable $e) { $this->exceptionHandler($e); } }
/** * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath) { self::$instance = $this; self::$sleeper = new \Threaded(); $this->autoloader = $autoloader; $this->logger = $logger; $this->filePath = $filePath; try { if (!file_exists($dataPath . "crashdumps/")) { mkdir($dataPath . "crashdumps/", 0777); } if (!file_exists($dataPath . "worlds/")) { mkdir($dataPath . "worlds/", 0777); } if (!file_exists($dataPath . "players/")) { mkdir($dataPath . "players/", 0777); } if (!file_exists($pluginPath)) { mkdir($pluginPath, 0777); } $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->console = new CommandReader($logger); $version = new VersionString($this->getPocketMineVersion()); $reloadpreConfig = false; $this->logger->info("Loading pocketmine.yml..."); if (!file_exists($this->dataPath . "pocketmine.yml")) { //$content = $this->translateConfig(file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"),"eng"); $content = \file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); @\file_put_contents($this->dataPath . "pocketmine.yml", $content); } else { $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $internal_config = yaml_parse(file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml")); if ($this->getProperty("version", 0) < $internal_config['version']) { $this->logger->warning("Outdated pocketmine.yml"); if ($this->getProperty("settings.config-update", true)) { $this->logger->info("Updating pocketmine.yml..."); if (!$this->getProperty("temp-file", false)) { rename($this->dataPath . "pocketmine.yml", $this->dataPath . "pocketmine.yml." . time() . ".bak"); } //$content = $this->translateConfig(file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"),$this->getProperty("settings.language", "eng")); $content = \file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); @\file_put_contents($this->dataPath . "pocketmine.yml", $content); } else { $this->logger->info("Ignore outdated pocketmine.yml"); } } unset($inernal_config); } $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $this->logger->info("Loading server properties..."); $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(random_bytes(20)), 3, 10), "auto-save" => true, "online-mode" => false]); if (!extension_loaded("openssl") && $this->getConfigBoolean("online-mode", false)) { $this->logger->warning("The OpenSSL extension is not loaded, and this is required for XBOX authentication to work. If you want to use Xbox Live auth, please use PHP binarys with OpenSSL, or recompile PHP with the OpenSSL extension."); //TODO:TRANSLATE $this->setConfigBool("online-mode", false); } if (extension_loaded("xdebug")) { if (!$this->getProperty("debug.allow-xdebug", false)) { $this->logger->critical("Please do not use a PHP installation with the xDebug extension loaded for a Production server. If you do want to use it however, set debug.allow-xdebug to true."); //TODO:TRANSLATE return; } else { $this->logger->warning("xDebug is enabled, this decreases Performance. Use this for development purposes only."); //TODO:TRANSLATE } } if (!$this->getProperty("I/O.log-to-file", true)) { $this->logger->disable(); $this->logger->info("MainLogger will not write to server.log"); //TODO:TRANSLATE } else { $this->logger->enable(); $this->logger->info("MainLogger will write to server.log"); //TODO:TRANSLATE } $this->forceLanguage = $this->getProperty("settings.force-language", false); $this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE)); $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()])); $this->memoryManager = new MemoryManager($this); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getVersion()])); if (($poolSize = $this->getProperty("settings.async-workers", "auto")) === "auto") { $poolSize = ServerScheduler::$WORKERS; $processors = Utils::getCoreCount() - 2; if ($processors > 0) { $poolSize = max(1, $processors); } } ServerScheduler::$WORKERS = $poolSize; if ($this->getProperty("network.batch-threshold", 256) >= 0) { Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); } else { Network::$BATCH_THRESHOLD = -1; } $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); $this->networkCompressionAsync = $this->getProperty("network.async-compression", true); $this->autoTickRate = (bool) $this->getProperty("level-settings.auto-tick-rate", true); $this->autoTickRateLimit = (int) $this->getProperty("level-settings.auto-tick-rate-limit", 20); $this->alwaysTickPlayers = (int) $this->getProperty("level-settings.always-tick-players", false); $this->baseTickRate = (int) $this->getProperty("level-settings.base-tick-rate", 1); $this->scheduler = new ServerScheduler(); if ($this->getConfigBoolean("enable-rcon", false) === true) { $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); $this->levelMetadata = new LevelMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) { @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt"); } @touch($this->dataPath . "banned-players.txt"); $this->banByName = new BanList($this->dataPath . "banned-players.txt"); $this->banByName->load(); @touch($this->dataPath . "banned-ips.txt"); $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) { $this->setConfigInt("difficulty", 3); } define('pocketmine\\DEBUG', (int) $this->getProperty("debug.level", 1)); ini_set('assert.exception', 1); if ($this->logger instanceof MainLogger) { $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } if (\pocketmine\DEBUG >= 0) { @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); } $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()])); define("BOOTUP_RANDOM", random_bytes(16)); $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId()); $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId()); $this->network = new Network($this); $this->network->setName($this->getMotd()); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), $this->getPocketMineVersion(), $this->getCodename(), $this->getApiVersion(), $this->getPocketMineBuild()])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()])); Timings::init(); $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); $this->registerEntities(); $this->registerTiles(); InventoryType::init(); Block::init(); Item::init(); Biome::init(); Effect::init(); Enchantment::init(); Attribute::init(); EnchantmentLevelTable::init(); Color::init(); $this->craftingManager = new CraftingManager(); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); $this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20); $this->pluginManager->registerInterface(PharPluginLoader::class); $this->pluginManager->registerInterface(ScriptPluginLoader::class); register_shutdown_function([$this, "crashDump"]); $this->queryRegenerateTask = new QueryRegenerateEvent($this, 5); $this->network->registerInterface(new RakLibInterface($this)); $this->pluginManager->loadPlugins($this->pluginPath); $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "jenkins.clearskyteam.org")); $this->enablePlugins(PluginLoadOrder::STARTUP); LevelProviderManager::addProvider($this, Anvil::class); LevelProviderManager::addProvider($this, McRegion::class); if (extension_loaded("leveldb")) { $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable")); LevelProviderManager::addProvider($this, LevelDB::class); } Generator::addGenerator(Flat::class, "flat"); Generator::addGenerator(Normal::class, "normal"); Generator::addGenerator(Normal::class, "default"); Generator::addGenerator(Nether::class, "hell"); Generator::addGenerator(Nether::class, "nether"); foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) { if ($this->loadLevel($name) === false) { $seed = $this->getProperty("worlds.{$name}.seed", time()); $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default"))); $generator = Generator::getGenerator(array_shift($options)); if (count($options) > 0) { $options = ["preset" => implode(":", $options)]; } else { $options = []; } $this->generateLevel($name, $seed, $generator, $options); } } if ($this->getDefaultLevel() === null) { $default = $this->getConfigString("level-name", "world"); if (trim($default) == "") { $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } if ($this->loadLevel($default) === false) { $seed = getopt("", ["level-seed::"])["level-seed"] ?? $this->properties->get("level-seed", time()); if (!is_numeric($seed) or bccomp($seed, "9223372036854775807") > 0) { $seed = Utils::javaStringHash($seed); } elseif (PHP_INT_SIZE === 8) { $seed = (int) $seed; } $this->generateLevel($default, $seed === 0 ? time() : $seed); } $this->setDefaultLevel($this->getLevelByName($default)); } $this->properties->save(true); if (!$this->getDefaultLevel() instanceof Level) { $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError")); $this->forceShutdown(); return; } if ($this->getProperty("ticks-per.autosave", 6000) > 0) { $this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000); } $this->enablePlugins(PluginLoadOrder::POSTWORLD); $this->start(); } catch (\Throwable $e) { $this->exceptionHandler($e); } }
public function createHell() { $generator = Generator::getGenerator("nether"); $bool = $this->getServer()->generateLevel("nether", null, $generator); if (!$this->getServer()->getLevelByName("nether") instanceof Level) { $this->getServer()->loadLevel("nether"); } if (!$bool) { $level = $this->getServer()->getLevelByName("nether"); if ($level instanceof Level) { $spawn = $level->getSafeSpawn(); $level->generateChunk($spawn->x, $spawn->z); $x = $spawn->x; $y = $spawn->y; $z = $spawn->z; $hellDoorData = $this->locationProvider->getLocationToName("@hellLocation"); $hellDoorData->savePosition(new Position($x, $y + 2, $z, $level)); $z -= 2; // DOOR CREATE $doorLength = 6; $doorHeight = 10; $portalBlock = new Block(90); $vector = new Vector3($x, $y, $z); $centerX = $x + $doorLength / 2; for ($dx = 0; $dx <= $doorLength - 1; $dx++) { $level->setBlock($vector->setComponents($centerX + $dx, $y, $z), $portalBlock); $level->setBlock($vector->setComponents($centerX + $dx, $y + $doorHeight, $z), $portalBlock); } for ($dy = 0; $dy <= $doorHeight - 1; $dy++) { $level->setBlock($vector->setComponents($centerX - $doorLength / 2, $y + $dy, $z), $portalBlock); $level->setBlock($vector->setComponents($centerX + $doorLength / 2, $y + $dy, $z), $portalBlock); } $startX = $centerX - $doorLength / 2; $startY = $y; $startZ = $z; $endX = $centerX + $doorLength / 2; $endY = $y + $doorHeight; $endZ = $z; if ($startX > $endX) { $backup = $endX; $endX = $startX; $startX = $backup; } if ($startY > $endY) { $backup = $endY; $endY = $startY; $startY = $backup; } if ($startZ > $endZ) { $backup = $endZ; $endZ = $startZ; $startZ = $backup; } $startY++; $endY = $endY - 2; if ($startZ == $endZ) { $startX++; $endX--; } else { $startZ++; $endZ--; } for ($x = $startX; $x <= $endX; $x++) { for ($y = $startY; $y <= $endY; $y++) { for ($z = $startZ; $z <= $endZ; $z++) { $level->setBlock($vector->setComponents($x, $y, $z), $portalBlock); } } } } } }
public function onEnable() { //$this->getServer()->getGenerationManager()->addNamespace(__NAMESPACE__, realpath(dirname(__FILE__) . "/../..")); Generator::addGenerator(SkyGridGenerator::class, "skygrid"); }
/** * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath) { self::$instance = $this; $this->autoloader = $autoloader; $this->logger = $logger; $this->filePath = $filePath; if (!file_exists($dataPath . "worlds/")) { mkdir($dataPath . "worlds/", 0777); } if (!file_exists($dataPath . "players/")) { mkdir($dataPath . "players/", 0777); } if (!file_exists($pluginPath)) { mkdir($pluginPath, 0777); } $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->console = new CommandReader(); $version = new VersionString($this->getPocketMineVersion()); $this->logger->info("Starting Minecraft: PE server version " . TextFormat::AQUA . $this->getVersion()); $this->logger->info("Loading pocketmine-soft.yml..."); if (!file_exists($this->dataPath . "pocketmine-soft.yml")) { $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine-soft.yml"); @file_put_contents($this->dataPath . "pocketmine-soft.yml", $content); } $this->softConfig = new Config($this->dataPath . "pocketmine-soft.yml", Config::YAML, []); $this->logger->info("Loading pocketmine.yml..."); if (!file_exists($this->dataPath . "pocketmine.yml")) { $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); @file_put_contents($this->dataPath . "pocketmine.yml", $content); } $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $this->logger->info("Loading server properties..."); $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "memory-limit" => "256M", "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true]); ServerScheduler::$WORKERS = 4; if ($this->getProperty("network.batch-threshold", 256) >= 0) { Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); } else { Network::$BATCH_THRESHOLD = -1; } $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); $this->networkCompressionAsync = $this->getProperty("network.async-compression", true); $this->scheduler = new ServerScheduler(); if ($this->getConfigBoolean("enable-rcon", false) === true) { $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); $this->levelMetadata = new LevelMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) { @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt"); } @touch($this->dataPath . "banned-players.txt"); $this->banByName = new BanList($this->dataPath . "banned-players.txt"); $this->banByName->load(); @touch($this->dataPath . "banned-ips.txt"); $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); if (($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false) { $value = ["M" => 1, "G" => 1024]; $real = (int) substr($memory, 0, -1) * $value[substr($memory, -1)]; if ($real < 128) { $this->logger->warning($this->getName() . " may not work right with less than 128MB of RAM", true, true, 0); } @ini_set("memory_limit", $memory); } else { $this->setConfigString("memory-limit", "256M"); } $this->network = new Network($this); if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) { $this->setConfigInt("difficulty", 3); } define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1)); if ($this->logger instanceof MainLogger) { $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } define("ADVANCED_CACHE", $this->getProperty("settings.advanced-cache", false)); if (ADVANCED_CACHE == true) { $this->logger->info("Advanced cache enabled"); } Level::$COMPRESSION_LEVEL = $this->getProperty("chunk-sending.compression-level", 8); if (defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0) { @\cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); } $this->logger->info("Starting Minecraft PE server on " . ($this->getIp() === "" ? "*" : $this->getIp()) . ":" . $this->getPort()); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); $this->addInterface($this->mainInterface = new RakLibInterface($this)); $this->logger->info("This server is running " . $this->getName() . " version " . ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE . " \"" . $this->getCodename() . "\" (API " . $this->getApiVersion() . ")"); $this->logger->info($this->getName() . " is distributed under the LGPL License"); PluginManager::$pluginParentTimer = new TimingsHandler("** Plugins"); Timings::init(); $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); $this->registerEntities(); $this->registerTiles(); InventoryType::init(); Block::init(); Item::init(); TextWrapper::init(); $this->craftingManager = new CraftingManager(); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); $this->pluginManager->registerInterface(PharPluginLoader::class); \set_exception_handler([$this, "exceptionHandler"]); register_shutdown_function([$this, "crashDump"]); $plugins = $this->pluginManager->loadPlugins($this->pluginPath); $configPlugins = $this->getAdvancedProperty("plugins", []); if (count($configPlugins) > 0) { $this->getLogger()->info("Checking extra plugins"); $loadNew = false; foreach ($configPlugins as $plugin => $download) { if (!isset($plugins[$plugin])) { $path = $this->pluginPath . "/" . $plugin . ".phar"; if (substr($download, 0, 4) === "http") { $this->getLogger()->info("Downloading " . $plugin); file_put_contents($path, Utils::getURL($download)); } else { file_put_contents($path, file_get_contents($download)); } $loadNew = true; } } if ($loadNew) { $this->pluginManager->loadPlugins($this->pluginPath); } } $this->enablePlugins(PluginLoadOrder::STARTUP); if ($this->getProperty("chunk-generation.use-async", true)) { $this->generationManager = new GenerationRequestManager($this); } else { $this->generationManager = new GenerationInstanceManager($this); } LevelProviderManager::addProvider($this, Anvil::class); LevelProviderManager::addProvider($this, McRegion::class); if (extension_loaded("leveldb")) { $this->logger->debug("Enabling LevelDB support"); LevelProviderManager::addProvider($this, LevelDB::class); } Generator::addGenerator(Flat::class, "flat"); Generator::addGenerator(Normal::class, "normal"); Generator::addGenerator(Normal::class, "default"); foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) { if ($this->loadLevel($name) === false) { $seed = $this->getProperty("worlds.{$name}.seed", time()); $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default"))); $generator = Generator::getGenerator(array_shift($options)); if (count($options) > 0) { $options = ["preset" => implode(":", $options)]; } else { $options = []; } $this->generateLevel($name, $seed, $generator, $options); } } if ($this->getDefaultLevel() === null) { $default = $this->getConfigString("level-name", "world"); if (trim($default) == "") { $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } if ($this->loadLevel($default) === false) { $seed = $this->getConfigInt("level-seed", time()); $this->generateLevel($default, $seed === 0 ? time() : $seed); } $this->setDefaultLevel($this->getLevelByName($default)); } $this->properties->save(); if (!$this->getDefaultLevel() instanceof Level) { $this->getLogger()->emergency("No default level has been loaded"); $this->forceShutdown(); return; } $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([Cache::class, "cleanup"]), $this->getProperty("ticks-per.cache-cleanup", 900), $this->getProperty("ticks-per.cache-cleanup", 900)); if ($this->getAutoSave() and $this->getProperty("ticks-per.autosave", 6000) > 0) { $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doAutoSave"]), $this->getProperty("ticks-per.autosave", 6000), $this->getProperty("ticks-per.autosave", 6000)); } if ($this->getProperty("chunk-gc.period-in-ticks", 600) > 0) { $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doLevelGC"]), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600)); } $this->scheduler->scheduleRepeatingTask(new GarbageCollectionTask(), 900); $this->enablePlugins(PluginLoadOrder::POSTWORLD); if ($this->getAdvancedProperty("main.player-shuffle", 0) > 0) { $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "shufflePlayers"]), $this->getAdvancedProperty("main.player-shuffle", 0), $this->getAdvancedProperty("main.player-shuffle", 0)); } $this->start(); }
public function onEnable() { Generator::addGenerator(WorldGen::class, WorldGen::NAME); }
/** * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath) { self::$instance = $this; $this->autoloader = $autoloader; $this->logger = $logger; $this->filePath = $filePath; if (!file_exists($dataPath . "worlds/")) { mkdir($dataPath . "worlds/", 0777); } if (!file_exists($dataPath . "players/")) { mkdir($dataPath . "players/", 0777); } if (!file_exists($dataPath . "CrashDump/")) { mkdir($dataPath . "CrashDump/", 0777); } if (!file_exists($pluginPath)) { mkdir($pluginPath, 0777); } $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->console = new CommandReader(); $version = new VersionString($this->getPocketMineVersion()); $this->logger->info(TextFormat::GREEN . " ____ _ _ __ __ _ " . TextFormat::AQUA . " _____ _ _ _ "); $this->logger->info(TextFormat::GREEN . " | _ \\ ___ ___| | _____| |_| \\/ (_)_ __ ___ " . TextFormat::AQUA . "| ____| (_) |_ ___ "); $this->logger->info(TextFormat::GREEN . " | |_) / _ \\ / __| |/ / _ \\ __| |\\/| | | '_ \\ / _ \\ _____ " . TextFormat::AQUA . "| _| | | | __/ _ \\ "); $this->logger->info(TextFormat::GREEN . " | __/ (_) | (__| < __/ |_| | | | | | | | __/ |_____| " . TextFormat::AQUA . "| |___| | | || __/"); $this->logger->info(TextFormat::GREEN . " |_| \\___/ \\___|_|\\_\\___|\\__|_| |_|_|_| |_|\\___| " . TextFormat::AQUA . "|_____|_|_|\\__\\___|"); $this->logger->info(TextFormat::GREEN . " Version: " . TextFormat::AQUA . $version); $this->logger->info("Loading pocketmine.yml..."); if (!file_exists($this->dataPath . "pocketmine.yml")) { $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); if ($version->isDev()) { $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content); } @file_put_contents($this->dataPath . "pocketmine.yml", $content); } $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $this->logger->info("Loading server properties..."); $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true]); $this->forceLanguage = $this->getProperty("settings.force-language", false); $this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE)); $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()])); $this->memoryManager = new MemoryManager($this); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getVersion()])); if (($poolSize = $this->getProperty("settings.async-workers", "auto")) === "auto") { $poolSize = ServerScheduler::$WORKERS; $processors = Utils::getCoreCount() - 2; if ($processors > 0) { $poolSize = max(1, $processors); } } ServerScheduler::$WORKERS = $poolSize; if ($this->getProperty("network.batch-threshold", 256) >= 0) { Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); } else { Network::$BATCH_THRESHOLD = -1; } $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); $this->networkCompressionAsync = $this->getProperty("network.async-compression", true); $this->autoTickRate = (bool) $this->getProperty("level-settings.auto-tick-rate", true); $this->autoTickRateLimit = (int) $this->getProperty("level-settings.auto-tick-rate-limit", 20); $this->alwaysTickPlayers = (int) $this->getProperty("level-settings.always-tick-players", false); $this->baseTickRate = (int) $this->getProperty("level-settings.base-tick-rate", 1); $this->scheduler = new ServerScheduler(); if ($this->getConfigBoolean("enable-rcon", false) === true) { $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); $this->levelMetadata = new LevelMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) { @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt"); } @touch($this->dataPath . "banned-players.txt"); $this->banByName = new BanList($this->dataPath . "banned-players.txt"); $this->banByName->load(); @touch($this->dataPath . "banned-ips.txt"); $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) { $this->setConfigInt("difficulty", 3); } define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1)); if ($this->logger instanceof MainLogger) { $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } if (\pocketmine\DEBUG >= 0) { @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); } $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()])); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId()); $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId()); $this->network = new Network($this); $this->network->setName($this->getMotd()); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE, $this->getCodename(), $this->getApiVersion()])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()])); Timings::init(); $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); $this->registerEntities(); $this->registerTiles(); InventoryType::init(); Block::init(); Item::init(); Biome::init(); Effect::init(); Enchantment::init(); Attribute::init(); /** TODO: @deprecated */ TextWrapper::init(); $this->craftingManager = new CraftingManager(); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); $this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20); $this->pluginManager->registerInterface(PharPluginLoader::class); $this->pluginManager->registerInterface(ScriptPluginLoader::class); set_exception_handler([$this, "exceptionHandler"]); register_shutdown_function([$this, "crashDump"]); $this->queryRegenerateTask = new QueryRegenerateEvent($this, 5); $this->network->registerInterface(new RakLibInterface($this)); $this->pluginManager->loadPlugins($this->pluginPath); $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net")); $this->enablePlugins(PluginLoadOrder::STARTUP); LevelProviderManager::addProvider($this, Anvil::class); LevelProviderManager::addProvider($this, McRegion::class); if (extension_loaded("leveldb")) { $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable")); LevelProviderManager::addProvider($this, LevelDB::class); } Generator::addGenerator(Flat::class, "flat"); Generator::addGenerator(Normal::class, "normal"); Generator::addGenerator(Normal::class, "default"); Generator::addGenerator(Nether::class, "hell"); Generator::addGenerator(Nether::class, "nether"); foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) { if ($this->loadLevel($name) === false) { $seed = $this->getProperty("worlds.{$name}.seed", time()); $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default"))); $generator = Generator::getGenerator(array_shift($options)); if (count($options) > 0) { $options = ["preset" => implode(":", $options)]; } else { $options = []; } $this->generateLevel($name, $seed, $generator, $options); } } if ($this->getDefaultLevel() === null) { $default = $this->getConfigString("level-name", "world"); if (trim($default) == "") { $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } if ($this->loadLevel($default) === false) { $seed = $this->getConfigInt("level-seed", time()); $this->generateLevel($default, $seed === 0 ? time() : $seed); } $this->setDefaultLevel($this->getLevelByName($default)); } $this->properties->save(true); if (!$this->getDefaultLevel() instanceof Level) { $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError")); $this->forceShutdown(); return; } if ($this->getProperty("ticks-per.autosave", 6000) > 0) { $this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000); } $this->enablePlugins(PluginLoadOrder::POSTWORLD); $this->start(); }
public function onEnable() { self::$instance = $this; $folder = $this->getDataFolder(); if (!is_dir($folder)) { mkdir($folder); } if (!is_dir($folder . "worlds")) { mkdir($folder . "worlds"); } Generator::addGenerator(MyPlotGenerator::class, "myplot"); $this->saveDefaultConfig(); $this->reloadConfig(); $this->getLogger()->info(TextFormat::GREEN . "Loading the Plot Framework!"); $this->getLogger()->warning(TextFormat::YELLOW . "It seems that you are running the development build of MyPlot! Thats cool, but it CAN be very, very buggy! Just be careful when using this plugin and report any issues to" . TextFormat::GOLD . " http://github.com/wiez/MyPlot/issues"); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); $this->getServer()->getCommandMap()->register(Commands::class, new Commands($this)); $cacheSize = $this->getConfig()->get("PlotCacheSize"); $cacheAll = $this->getConfig()->get("CacheAllPlots") == true; switch (strtolower($this->getConfig()->get("DataProvider"))) { case "sqlite": die("sqlite not supported for myplot in this fork"); $this->dataProvider = new SQLiteDataProvider($this, $cacheSize); break; default: die("only mysql supported for myplot in this fork"); $this->dataProvider = new SQLiteDataProvider($this, $cacheSize); break; case "mysql": $this->dataProvider = new MYSQLDataProvider($this, $cacheSize, $cacheAll); break; } if ($this->getConfig()->get("UseEconomy") == true) { if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) { $this->economyProvider = new EconomySProvider(); } elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) { $this->economyProvider = new PocketMoneyProvider($plugin); } else { $this->economyProvider = null; } } else { $this->economyProvider = null; } $this->usesVotingAPI = false; if ($this->getConfig()->get("UseMPServers_voting") == true) { $this->usesVotingAPI = true; $apiKey = $this->getConfig()->get("MPServers_voting_API_key"); $votingURL = $this->getConfig()->get("MPServers_voting_direct_URL"); $freePlotsBeforeVoting = $this->getConfig()->get("FreePlotsBeforeVoting"); $this->votingProvider = new VotingProvider($this, $apiKey, $freePlotsBeforeVoting, $votingURL); } $bcPlugin = $this->getServer()->getPluginManager()->getPlugin("BuddyChannels"); if (!is_null($bcPlugin)) { $chatFormatter = new \MyPlot\ChatMessageFormatter($this); } }
public function initLevel() { $generator = $this->generator; $this->generatorInstance = new $generator($this->provider->getGeneratorOptions()); $this->generatorInstance->init($this, new Random($this->getSeed())); $this->registerGenerator(); }
public function onLoad() { Generator::addGenerator(MineFarmGenerator::class, $this->name = "minefarm"); $this->getServer()->getLogger()->info("[MineFarm] MineFarmGenerator is Loaded"); }