本文整理匯總了PHP中pocketmine\level\generator\Generator::getGenerator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::getGenerator方法的具體用法?PHP Generator::getGenerator怎麽用?PHP Generator::getGenerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\level\generator\Generator
的用法示例。
在下文中一共展示了Generator::getGenerator方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onSCommand
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;
}
示例2: __construct
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::LITTLE_ENDIAN);
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->getData();
if ($levelData instanceof CompoundTag) {
$this->levelData = $levelData;
if (!isset($this->levelData["GameRules"])) {
$this->levelData["GameRules"] = (new GameRules())->getRules();
}
} else {
throw new LevelException("Invalid level.dat");
}
if (!isset($this->levelData->generatorName)) {
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
}
if (!isset($this->levelData->generatorOptions)) {
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
}
$this->db = new \LevelDB($this->path . "db", ["compression" => LEVELDB_ZLIB_COMPRESSION]);
}
示例3: onCommand
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;
}
示例4: __construct
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", "");
}
}
示例5: __construct
/**
* 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($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$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", 40);
$this->chunkGenerationQueueSize = (int) $this->server->getProperty("chunk-generation.queue-size", 8);
$this->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2);
$this->chunkTickList = [];
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true);
$this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false);
$this->timings = new LevelTimings($this);
$this->temporalPosition = new Position(0, 0, 0, $this);
$this->temporalVector = new Vector3(0, 0, 0);
$this->tickRate = 1;
}
示例6: __construct
/**
* 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);
}
示例7: __construct
//.........這裏部分代碼省略.........
$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();
}
示例8: __construct
//.........這裏部分代碼省略.........
$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();
}
示例9: __construct
/**
* 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($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$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->weatherEnabled = (bool) $this->getServer()->getProperty("weather-settings.enable-weather");
$this->weatherMinutes = $this->getServer()->getProperty("weather-settings.weather-minutes");
if ($this->weatherMinutes === strtolower("random") || $this->weatherMinutes === null) {
$this->weatherMinutes = mt_rand(3, 5);
}
if ($this->weatherEnabled === true) {
$this->raining = $this->provider->isRaining();
$this->rainTime = $this->provider->getRainTime();
if ($this->rainTime <= 0) {
$this->setRainTime($this->weatherMinutes * 20 * 60);
}
$this->randomWeather = mt_rand(0, 400);
$this->thundering = $this->provider->isThundering();
$this->thunderTime = $this->provider->getThunderTime();
if ($this->thunderTime <= 0) {
$this->setThunderTime($this->weatherMinutes * 20 * 60);
}
}
foreach ($this->getServer()->getProperty("disable-block-ticking", []) as $id) {
$ticked = isset($this->randomTickBlocks[$id]);
if ($ticked === true) {
unset($this->randomTickBlocks[$id]);
}
}
$this->updateRedstoneQueue = new ReversePriorityQueue();
$this->updateRedstoneQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$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", 40);
$this->chunkGenerationQueueSize = (int) $this->server->getProperty("chunk-generation.queue-size", 8);
$this->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2);
$this->chunkTickList = [];
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true);
$this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false);
$this->timings = new LevelTimings($this);
$this->temporalPosition = new Position(0, 0, 0, $this);
$this->temporalVector = new Vector3(0, 0, 0);
$this->temporalVector2 = new Vector3(0, 0, 0);
$this->tickRate = 1;
}
示例10: __construct
/**
* 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);
}
示例11: __construct
//.........這裏部分代碼省略.........
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);
}
}
示例12: __construct
//.........這裏部分代碼省略.........
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);
}
}
示例13: createHell
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);
}
}
}
}
}
}
示例14: __construct
/**
* 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, string $name, string $path, string $provider)
{
$this->blockStates = Block::$fullList;
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
$this->autoSave = $server->getAutoSave();
/** Weather Config Loader */
$this->rainprob = $this->getServer()->getProperty("level-settings.weather.rain.possibility", 10);
$this->raintime[] = $this->getServer()->getProperty("level-settings.weather.rain.time.min", 30);
$this->raintime[] = $this->getServer()->getProperty("level-settings.weather.rain.time.max", 120);
$this->rainfall[] = $this->getServer()->getProperty("level-settings.weather.rain.rainfall.min", 1000);
$this->rainfall[] = $this->getServer()->getProperty("level-settings.weather.rain.rainfall.max", 100000);
/** @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($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$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();
/** Set dimension */
if ($server->netherName == $this->folderName) {
$this->setDimension(self::DIMENSION_NETHER);
} else {
$this->setDimension(self::DIMENSION_NORMAL);
}
$this->gamerules = new GameRules($this->provider->getGameRules());
$this->getGameRule("doDaylightCycle") ? $this->startTime() : $this->stopTime();
/** Random ticking */
foreach ($this->getServer()->getProperty("chunk-ticking.disabled-randomly-ticking-blocks", []) as $id) {
$ticked = isset($this->randomTickBlocks[$id]);
if ($ticked === true) {
unset($this->randomTickBlocks[$id]);
}
}
$this->updateRedstoneQueue = new ReversePriorityQueue();
$this->updateRedstoneQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$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", 40);
$this->chunkGenerationQueueSize = (int) $this->server->getProperty("chunk-generation.queue-size", 8);
$this->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2);
$this->chunkTickList = [];
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true);
$this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false);
$this->timings = new LevelTimings($this);
$this->temporalPosition = new Position(0, 0, 0, $this);
$this->temporalVector = new Vector3(0, 0, 0);
$this->tickRate = 1;
}