public function __construct(Server $server, $timeout = 5) { $this->timeout = $timeout; $this->serverName = $server->getMotd(); $this->listPlugins = $server->getProperty("settings.query-plugins", true); $this->plugins = $server->getPluginManager()->getPlugins(); $this->players = []; foreach ($server->getOnlinePlayers() as $player) { if ($player->isOnline()) { $this->players[] = $player; } } if ($server->isDServerEnabled() and $server->dserverConfig["queryMaxPlayers"]) { $pc = $server->dserverConfig["queryMaxPlayers"]; } elseif ($server->isDServerEnabled() and $server->dserverConfig["queryAllPlayers"]) { $pc = $server->getDServerMaxPlayers(); } else { $pc = $server->getMaxPlayers(); } if ($server->isDServerEnabled() and $server->dserverConfig["queryPlayers"]) { $poc = $server->getDServerOnlinePlayers(); } else { $poc = count($this->players); } $this->gametype = ($server->getGamemode() & 0x1) === 0 ? "SMP" : "CMP"; $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion(); $this->map = $server->getDefaultLevel() === null ? "unknown" : $server->getDefaultLevel()->getName(); $this->numPlayers = $poc; $this->maxPlayers = $pc; $this->whitelist = $server->hasWhitelist() ? "on" : "off"; $this->port = $server->getPort(); $this->ip = $server->getIp(); }
public function __construct(Server $server) { $this->server = $server; $this->timeout = $server->getProperty("network.timeout", -1); $this->currentprotocol = $server->getProperty("network.protocol", 39); $this->networkversion = $server->getProperty("network.version", "0.13.2"); $this->identifiers = []; $this->rakLib = new RakLibServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getPort(), $this->server->getIp() === "" ? "0.0.0.0" : $this->server->getIp()); $this->interface = new ServerHandler($this->rakLib, $this); for ($i = 0; $i < 256; ++$i) { $this->channelCounts[$i] = 0; } }
public function getChannel() { $channel = strtolower($this->server->getProperty("auto-updater.preferred-channel", "stable")); if ($channel !== "stable" and $channel !== "beta" and $channel !== "development") { $channel = "stable"; } return $channel; }
public function getChannel() { $channel = strtolower($this->server->getProperty("auto-updater.preferred-channel", "ClearSky")); if ($channel !== "ClearSky" and $channel !== "ClearSky-php7") { $channel = "ClearSky"; } return $channel; }
private function init() { $this->memoryLimit = (int) $this->server->getProperty("memory.main-limit", 0) * 1024 * 1024; $defaultMemory = 1024; if (preg_match("/([0-9]+)([KMGkmg])/", $this->server->getConfigString("memory-limit", ""), $matches) > 0) { $m = (int) $matches[1]; if ($m <= 0) { $defaultMemory = 0; } else { switch (strtoupper($matches[2])) { case "K": $defaultMemory = $m / 1024; break; case "M": $defaultMemory = $m; break; case "G": $defaultMemory = $m * 1024; break; default: $defaultMemory = $m; break; } } } $hardLimit = (int) $this->server->getProperty("memory.main-hard-limit", $defaultMemory); if ($hardLimit <= 0) { ini_set("memory_limit", -1); } else { ini_set("memory_limit", $hardLimit . "M"); } $this->globalMemoryLimit = (int) $this->server->getProperty("memory.global-limit", 0) * 1024 * 1024; $this->checkRate = (int) $this->server->getProperty("memory.check-rate", 20); $this->continuousTrigger = (bool) $this->server->getProperty("memory.continuous-trigger", true); $this->continuousTriggerRate = (int) $this->server->getProperty("memory.continuous-trigger-rate", 30); $this->garbageCollectionPeriod = (int) $this->server->getProperty("memory.garbage-collection.period", 36000); $this->garbageCollectionTrigger = (bool) $this->server->getProperty("memory.garbage-collection.low-memory-trigger", true); $this->garbageCollectionAsync = (bool) $this->server->getProperty("memory.garbage-collection.collect-async-worker", true); $this->chunkLimit = (int) $this->server->getProperty("memory.max-chunks.trigger-limit", 96); $this->chunkCollect = (bool) $this->server->getProperty("memory.max-chunks.trigger-chunk-collect", true); $this->chunkTrigger = (bool) $this->server->getProperty("memory.max-chunks.low-memory-trigger", true); $this->chunkCache = (bool) $this->server->getProperty("memory.world-caches.disable-chunk-cache", true); $this->cacheTrigger = (bool) $this->server->getProperty("memory.world-caches.low-memory-trigger", true); gc_enable(); }
private function setDefaultCommands() { $this->register("pocketmine", new WeatherCommand("weather")); $this->register("pocketmine", new BanCidCommand("bancid")); $this->register("pocketmine", new PardonCidCommand("pardoncid")); $this->register("pocketmine", new BancidbynameCommand("bancidbyname")); $this->register("pocketmine", new BanipbynameCommand("banipbyname")); $this->register("pocketmine", new ExtractPharCommand("extractphar")); $this->register("pocketmine", new ExtractPluginCommand("extractplugin")); $this->register("pocketmine", new MakePluginCommand("makeplugin")); $this->register("pocketmine", new MakeServerCommand("ms")); //$this->register("pocketmine", new MakeServerCommand("makeserver")); $this->register("pocketmine", new LoadPluginCommand("loadplugin")); $this->register("pocketmine", new LvdatCommand("lvdat")); $this->register("pocketmine", new BiomeCommand("biome")); $this->register("pocketmine", new VersionCommand("version")); $this->register("pocketmine", new PluginsCommand("plugins")); $this->register("pocketmine", new SeedCommand("seed")); $this->register("pocketmine", new HelpCommand("help")); $this->register("pocketmine", new StopCommand("stop")); $this->register("pocketmine", new TellCommand("tell")); $this->register("pocketmine", new DefaultGamemodeCommand("defaultgamemode")); $this->register("pocketmine", new BanCommand("ban")); $this->register("pocketmine", new BanIpCommand("ban-ip")); $this->register("pocketmine", new BanListCommand("banlist")); $this->register("pocketmine", new PardonCommand("pardon")); $this->register("pocketmine", new PardonIpCommand("pardon-ip")); $this->register("pocketmine", new SayCommand("say")); $this->register("pocketmine", new MeCommand("me")); $this->register("pocketmine", new ListCommand("list")); $this->register("pocketmine", new DifficultyCommand("difficulty")); $this->register("pocketmine", new KickCommand("kick")); $this->register("pocketmine", new OpCommand("op")); $this->register("pocketmine", new DeopCommand("deop")); $this->register("pocketmine", new WhitelistCommand("whitelist")); $this->register("pocketmine", new SaveOnCommand("save-on")); $this->register("pocketmine", new SaveOffCommand("save-off")); $this->register("pocketmine", new SaveCommand("save-all")); $this->register("pocketmine", new GiveCommand("give")); $this->register("pocketmine", new EffectCommand("effect")); $this->register("pocketmine", new EnchantCommand("enchant")); $this->register("pocketmine", new ParticleCommand("particle")); $this->register("pocketmine", new GamemodeCommand("gamemode")); $this->register("pocketmine", new KillCommand("kill")); $this->register("pocketmine", new SpawnpointCommand("spawnpoint")); $this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn")); $this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TimeCommand("time")); $this->register("pocketmine", new TimingsCommand("timings")); $this->register("pocketmine", new ReloadCommand("reload")); $this->register("pocketmine", new XpCommand("xp")); if ($this->server->getProperty("debug.commands", false)) { $this->register("pocketmine", new StatusCommand("status")); $this->register("pocketmine", new GarbageCollectorCommand("gc")); $this->register("pocketmine", new DumpMemoryCommand("dumpmemory")); } }
public function __construct(Server $server, $endpoint) { $this->server = $server; $this->endpoint = "http://{$endpoint}/api/"; if ($server->getProperty("auto-updater.enabled", true)) { $this->check(); if ($this->hasUpdate()) { if ($this->server->getProperty("auto-updater.on-update.warn-console", true)) { $this->showConsoleUpdate(); } } } }
public function __construct(Server $server, $timeout = 5) { $this->timeout = $timeout; $this->serverName = $server->getMotd(); $this->listPlugins = $server->getProperty("settings.query-plugins", true); $this->plugins = str_replace(" ", "_", $server->getPluginManager()->getPlugins()); $this->players = []; foreach ($server->getOnlinePlayers() as $player) { if ($player->isOnline()) { $this->players[] = $player; } } if ($server->isDServerEnabled() and $server->dserverConfig["queryMaxPlayers"]) { $pc = $server->dserverConfig["queryMaxPlayers"]; } elseif ($server->isDServerEnabled() and $server->dserverConfig["queryAllPlayers"]) { $pc = $server->getDServerMaxPlayers(); } else { $pc = $server->getMaxPlayers(); } if ($server->isDServerEnabled() and $server->dserverConfig["queryPlayers"]) { $poc = $server->getDServerOnlinePlayers(); } else { $poc = count($this->players); } switch ($server->getGamemode()) { case 0: $this->gametype = "Survival"; break; case 1: $this->gametype = "Creative"; break; case 2: $this->gametype = "Adventure"; break; case 3: $this->gametype = "Spectator"; break; } $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion(); $this->map = $server->getDefaultLevel() === null ? "unknown" : $server->getDefaultLevel()->getName(); $this->numPlayers = $poc; $this->maxPlayers = $pc; $this->whitelist = $server->hasWhitelist() ? "on" : "off"; $this->port = $server->getPort(); $this->ip = $server->getIp(); $this->motd_version = $server->getMPVersion(); }
public function __construct(Server $server, $type, $playerList = []) { $endpoint = "http://" . $server->getProperty("anonymous-statistics.host", "stats.pocketmine.net") . "/"; $data = []; $data["uniqueServerId"] = $server->getServerUniqueId()->toString(); $data["uniqueMachineId"] = Utils::getMachineUniqueId()->toString(); $data["uniqueRequestId"] = UUID::fromData($server->getServerUniqueId(), microtime(true))->toString(); switch ($type) { case self::TYPE_OPEN: $data["event"] = "open"; $version = new VersionString(); $data["server"] = ["port" => $server->getPort(), "software" => $server->getName(), "fullVersion" => $version->get(true), "version" => $version->get(), "build" => $version->getBuild(), "api" => $server->getApiVersion(), "minecraftVersion" => $server->getVersion(), "protocol" => Info::CURRENT_PROTOCOL]; $data["system"] = ["operatingSystem" => Utils::getOS(), "cores" => Utils::getCoreCount(), "phpVersion" => PHP_VERSION, "machine" => php_uname("a"), "release" => php_uname("r"), "platform" => php_uname("i")]; $data["players"] = ["count" => 0, "limit" => $server->getMaxPlayers()]; $plugins = []; foreach ($server->getPluginManager()->getPlugins() as $p) { $d = $p->getDescription(); $plugins[$d->getName()] = ["name" => $d->getName(), "version" => $d->getVersion(), "enabled" => $p->isEnabled()]; } $data["plugins"] = $plugins; break; case self::TYPE_STATUS: $data["event"] = "status"; $data["server"] = ["ticksPerSecond" => $server->getTicksPerSecondAverage(), "tickUsage" => $server->getTickUsageAverage(), "ticks" => $server->getTick()]; //This anonymizes the user ids so they cannot be reversed to the original foreach ($playerList as $k => $v) { $playerList[$k] = md5($v); } $players = []; foreach ($server->getOnlinePlayers() as $p) { if ($p->isOnline()) { $players[] = md5($p->getUniqueId()->toBinary()); } } $data["players"] = ["count" => count($players), "limit" => $server->getMaxPlayers(), "currentList" => $players, "historyList" => array_values($playerList)]; $info = Utils::getMemoryUsage(true); $data["system"] = ["mainMemory" => $info[0], "totalMemory" => $info[1], "availableMemory" => $info[2], "threadCount" => Utils::getThreadCount()]; break; case self::TYPE_CLOSE: $data["event"] = "close"; $data["crashing"] = $server->isRunning(); break; } $this->endpoint = $endpoint . "api/post"; $this->data = json_encode($data); }
private function setDefaultCommands() { $this->register("pocketmine", new VersionCommand("version")); $this->register("pocketmine", new PluginsCommand("plugins")); $this->register("pocketmine", new SeedCommand("seed")); $this->register("pocketmine", new HelpCommand("help")); $this->register("pocketmine", new StopCommand("stop")); $this->register("pocketmine", new TellCommand("tell")); $this->register("pocketmine", new DefaultGamemodeCommand("defaultgamemode")); $this->register("pocketmine", new BanCommand("ban")); $this->register("pocketmine", new BanIpCommand("ban-ip")); $this->register("pocketmine", new BanListCommand("banlist")); $this->register("pocketmine", new PardonCommand("pardon")); $this->register("pocketmine", new PardonIpCommand("pardon-ip")); $this->register("pocketmine", new SayCommand("say")); $this->register("pocketmine", new MeCommand("me")); $this->register("pocketmine", new ListCommand("list")); $this->register("pocketmine", new DifficultyCommand("difficulty")); $this->register("pocketmine", new KickCommand("kick")); $this->register("pocketmine", new OpCommand("op")); $this->register("pocketmine", new DeopCommand("deop")); $this->register("pocketmine", new WhitelistCommand("whitelist")); $this->register("pocketmine", new SaveOnCommand("save-on")); $this->register("pocketmine", new SaveOffCommand("save-off")); $this->register("pocketmine", new SaveCommand("save-all")); $this->register("pocketmine", new GiveCommand("give")); $this->register("pocketmine", new EffectCommand("effect")); $this->register("pocketmine", new ParticleCommand("particle")); $this->register("pocketmine", new GamemodeCommand("gamemode")); $this->register("pocketmine", new KillCommand("kill")); $this->register("pocketmine", new SpawnpointCommand("spawnpoint")); $this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn")); $this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TimeCommand("time")); $this->register("pocketmine", new TimingsCommand("timings")); $this->register("pocketmine", new ReloadCommand("reload")); if ($this->server->getProperty("debug.commands", false) === true) { $this->register("pocketmine", new StatusCommand("status")); } }
public function __construct(Server $server, $timeout = 5) { $this->timeout = $timeout; $this->serverName = $server->getServerName(); $this->listPlugins = $server->getProperty("settings.query-plugins", \true); $this->plugins = $server->getPluginManager()->getPlugins(); $this->players = []; foreach ($server->getOnlinePlayers() as $player) { if ($player->isOnline()) { $this->players[] = $player; } } $this->gametype = ($server->getGamemode() & 0x1) === 0 ? "SMP" : "CMP"; $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion(); $this->map = $server->getDefaultLevel() === \null ? "unknown" : $server->getDefaultLevel()->getName(); $this->numPlayers = \count($this->players); $this->maxPlayers = $server->getMaxPlayers(); $this->whitelist = $server->hasWhitelist() ? "on" : "off"; $this->port = $server->getPort(); $this->ip = $server->getIp(); }
/** * Registers all the events in the given Listener class * * @param Listener $listener * @param Plugin $plugin * * @throws PluginException */ public function registerEvents(Listener $listener, Plugin $plugin) { if (!$plugin->isEnabled()) { throw new PluginException("Plugin attempted to register " . \get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(\get_class($listener)); foreach ($reflection->getMethods() as $method) { if (!$method->isStatic()) { $priority = EventPriority::NORMAL; $ignoreCancelled = \false; if (\preg_match("/^[\t ]*\\* @priority[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = \strtoupper($matches[1]); if (\defined(EventPriority::class . "::" . $matches[1])) { $priority = \constant(EventPriority::class . "::" . $matches[1]); } } if (\preg_match("/^[\t ]*\\* @ignoreCancelled[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = \strtolower($matches[1]); if ($matches[1] === "false") { $ignoreCancelled = \false; } elseif ($matches[1] === "true") { $ignoreCancelled = \true; } } $parameters = $method->getParameters(); if (\count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and \is_subclass_of($parameters[0]->getClass()->getName(), Event::class)) { $class = $parameters[0]->getClass()->getName(); $reflection = new \ReflectionClass($class); if (\strpos((string) $reflection->getDocComment(), "@deprecated") !== \false and $this->server->getProperty("settings.deprecated-verbose", \true)) { $this->server->getLogger()->warning('Plugin ' . $plugin->getName() . ' has registered a listener for ' . $class . ' on method ' . \get_class($listener) . '->' . $method->getName() . '(), but the event is Deprecated.'); } $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled); } } } }
/** * Registers all the events in the given Listener class * * @param Listener $listener * @param Plugin $plugin * * @throws \Exception */ public function registerEvents(Listener $listener, Plugin $plugin) { if (!$plugin->isEnabled()) { throw new \Exception("Plugin attempted to register " . get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(get_class($listener)); foreach ($reflection->getMethods() as $method) { if (!$method->isStatic()) { $priority = EventPriority::NORMAL; $ignoreCancelled = false; if (preg_match("/^[\t ]*\\* @priority[\t ]{1,}([a-zA-Z]{1,})\$/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtoupper($matches[1]); if (defined("pocketmine\\event\\EventPriority::" . $matches[1])) { $priority = constant("pocketmine\\event\\EventPriority::" . $matches[1]); } } if (preg_match("/^[\t ]*\\* @ignoreCancelled[\t ]{1,}([a-zA-Z]{1,})\$/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtolower($matches[1]); if ($matches[1] === "false") { $ignoreCancelled = false; } elseif ($matches[1] === "true") { $ignoreCancelled = true; } } $parameters = $method->getParameters(); if (count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and is_subclass_of($parameters[0]->getClass()->getName(), "pocketmine\\event\\Event")) { $class = $parameters[0]->getClass()->getName(); $reflection = new \ReflectionClass($class); if (preg_match("/^[\t ]*\\* @deprecated[\t ]{1,}\$/m", (string) $reflection->getDocComment(), $matches) > 0 and $this->server->getProperty("settings.deprecated-verbose", true)) { $this->server->getLogger()->warning('"' . $plugin->getName() . '" has registered a listener for ' . $class . ' on method "' . get_class($listener) . '::' . $method . ', but the event is Deprecated.'); } $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled); } } } }
/** * Registers all the events in the given Listener class * * @param Listener $listener * @param Plugin $plugin * * @throws PluginException */ public function registerEvents(Listener $listener, Plugin $plugin) { if (!$plugin->isEnabled()) { throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(get_class($listener)); foreach ($reflection->getMethods() as $method) { if (!$method->isStatic()) { $priority = EventPriority::NORMAL; $ignoreCancelled = false; if (preg_match("/^[\t ]*\\* @priority[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtoupper($matches[1]); if (defined(EventPriority::class . "::" . $matches[1])) { $priority = constant(EventPriority::class . "::" . $matches[1]); } } if (preg_match("/^[\t ]*\\* @ignoreCancelled[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtolower($matches[1]); if ($matches[1] === "false") { $ignoreCancelled = false; } elseif ($matches[1] === "true") { $ignoreCancelled = true; } } $parameters = $method->getParameters(); if (count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and is_subclass_of($parameters[0]->getClass()->getName(), Event::class)) { $class = $parameters[0]->getClass()->getName(); $reflection = new \ReflectionClass($class); if (strpos((string) $reflection->getDocComment(), "@deprecated") !== false and $this->server->getProperty("settings.deprecated-verbose", true)) { $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.deprecatedEvent", [$plugin->getName(), $class, get_class($listener) . "->" . $method->getName() . "()"])); } $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled); } } } }
/** * 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->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); }
private function baseCrash() { global $lastExceptionError, $lastError; if (isset($lastExceptionError)) { $error = $lastExceptionError; } else { $error = (array) error_get_last(); $error["trace"] = @getTrace(3); $errorConversion = [E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED"]; $error["fullFile"] = $error["file"]; $error["file"] = cleanPath($error["file"]); $error["type"] = isset($errorConversion[$error["type"]]) ? $errorConversion[$error["type"]] : $error["type"]; if (($pos = strpos($error["message"], "\n")) !== false) { $error["message"] = substr($error["message"], 0, $pos); } } if (isset($lastError)) { $this->data["lastError"] = $lastError; } $this->data["error"] = $error; unset($this->data["error"]["fullFile"]); unset($this->data["error"]["trace"]); $this->addLine("Error: " . $error["message"]); $this->addLine("File: " . $error["file"]); $this->addLine("Line: " . $error["line"]); $this->addLine("Type: " . $error["type"]); if (strpos($error["file"], "src/pocketmine/") === false and strpos($error["file"], "src/raklib/") === false and file_exists($error["fullFile"])) { $this->addLine(); $this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN"); $this->data["plugin"] = true; $reflection = new \ReflectionClass(PluginBase::class); $file = $reflection->getProperty("file"); $file->setAccessible(true); foreach ($this->server->getPluginManager()->getPlugins() as $plugin) { $filePath = \pocketmine\cleanPath($file->getValue($plugin)); if (strpos($error["file"], $filePath) === 0) { $this->data["plugin"] = $plugin->getName(); $this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName()); break; } } } else { $this->data["plugin"] = false; } $this->addLine(); $this->addLine("Code:"); $this->data["code"] = []; if ($this->server->getProperty("auto-report.send-code", true) !== false) { $file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES); for ($l = max(0, $error["line"] - 10); $l < $error["line"] + 10; ++$l) { $this->addLine("[" . ($l + 1) . "] " . @$file[$l]); $this->data["code"][$l + 1] = @$file[$l]; } } $this->addLine(); $this->addLine("Backtrace:"); foreach ($this->data["trace"] = $error["trace"] as $line) { $this->addLine($line); } $this->addLine(); }
/** * 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); }
/** * @param Server $server * @param GenerationInstanceManager $manager */ public function __construct(Server $server, GenerationInstanceManager $manager) { $this->server = $server; $this->manager = $manager; $this->maxCount = $this->server->getProperty("chunk-generation.per-tick", 1); }
private function init() { $this->memoryLimit = (int) $this->server->getProperty("memory.main-limit", 320) * 1024 * 1024; $this->globalMemoryLimit = (int) $this->server->getProperty("memory.global-limit", 512) * 1024 * 1024; $this->checkRate = (int) $this->server->getProperty("memory.check-rate", 20); $this->continuousTrigger = (bool) $this->server->getProperty("memory.continuous-trigger", true); $this->continuousTriggerRate = (int) $this->server->getProperty("memory.continuous-trigger-rate", 30); $this->garbageCollectionPeriod = (int) $this->server->getProperty("memory.garbage-collection.period", 36000); $this->garbageCollectionTrigger = (bool) $this->server->getProperty("memory.garbage-collection.low-memory-trigger", true); $this->garbageCollectionAsync = (bool) $this->server->getProperty("memory.garbage-collection.collect-async-worker", true); $this->chunkLimit = (int) $this->server->getProperty("memory.max-chunks.trigger-limit", 96); $this->chunkCollect = (bool) $this->server->getProperty("memory.max-chunks.trigger-chunk-collect", true); $this->chunkTrigger = (bool) $this->server->getProperty("memory.max-chunks.low-memory-trigger", true); $this->chunkCache = (bool) $this->server->getProperty("memory.world-caches.disable-chunk-cache", true); $this->cacheTrigger = (bool) $this->server->getProperty("memory.world-caches.low-memory-trigger", true); gc_enable(); }
/** * @param Vector3 $pos * @param int $delay */ public function setRedstoneUpdate(Vector3 $pos, $delay, $type, $power) { if ($this->server->getProperty("redstone.enable", true)) { if (isset($this->updateRedstoneQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->updateRedstoneQueueIndex[$index]['delay'] <= $delay) { return; } $this->updateRedstoneQueueIndex[$index]['delay'] = $delay; $this->updateRedstoneQueueIndex[$index]['type'] = $type; $this->updateRedstoneQueueIndex[$index]['power'] = $power; $this->updateRedstoneQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); } return; }
/** * 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->getKatana()->console->system("Preparing level " . Terminal::$COLOR_WHITE . $this->getName()); $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->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2); $this->chunkTickList = []; $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); $this->temporalVector = new Vector3(0, 0, 0); $this->tickRate = 1; // Initialize chunk cache folder if ($this->server->getKatana()->getProperty("cache.save-to-disk", true) && !file_exists("chunk_cache/" . $this->getName() . "/")) { mkdir("chunk_cache/" . $this->getName() . "/", 0777); } }
/** * Tries to break a block using a item, including Player time checks if available * It'll try to lower the durability if Item is a tool, and set it to Air if broken. * * @param Vector3 $vector * @param Item &$item (if null, can break anything) * @param Player $player * @param bool $createParticles * * @return boolean */ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false) { $target = $this->getBlock($vector); //TODO: Adventure mode checks if ($item === null) { $item = Item::get(Item::AIR, 0, 0); } if ($player !== null) { $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false); if ($player->isSpectator() or !$player->isOp() and $player->isAdventure()) { $ev->setCancelled(); } if ($item instanceof Tool) { $item->setDamage($item->getDamage() + $item->getDamageStep($target)); $player->getInventory()->setItemInHand($item); } if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) { $ev->setCancelled(); } if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } $breakTime = $target->getBreakTime($item); if ($player->isCreative() and $breakTime > 0.15) { $breakTime = 0.15; } if ($player->hasEffect(Effect::SWIFTNESS)) { $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1); } if ($player->hasEffect(Effect::MINING_FATIGUE)) { $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1); } $breakTime -= 0.05; //1 tick compensation if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) { return false; } $player->lastBreak = microtime(true); $drops = $ev->getDrops(); if ($this->server->getProperty("experience.enable", true) and $this->server->getProperty("experience.break-drop", true) and $player->isSurvival()) { $exp = $target->getExperience(); $this->spawnExperienceOrb($vector->add(0, 1, 0), $exp); } } elseif ($item !== null and !$target->isBreakable($item)) { return false; } else { $drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops foreach ($drops as $k => $i) { $drops[$k] = Item::get($i[0], $i[1], $i[2]); } } $tag = $item->getNamedTagEntry("CanDestroy"); if ($tag instanceof Enum) { $canBreak = false; foreach ($tag as $v) { if ($v instanceof String) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canBreak = true; break; } } } if (!$canBreak) { return false; } } if ($createParticles) { $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4); if ($player !== null) { unset($players[$player->getLoaderId()]); } $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players); } $target->onBreak($item); $tile = $this->getTile($target); if ($tile !== null) { if ($tile instanceof InventoryHolder) { if ($tile instanceof Chest) { $tile->unpair(); } foreach ($tile->getInventory()->getContents() as $chestItem) { $this->dropItem($target, $chestItem); } } $tile->close(); } if ($item !== null) { $item->useOn($target); if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) { $item = Item::get(Item::AIR, 0, 0); } } if ($player === null or $player->isSurvival()) { foreach ($drops as $drop) { if ($drop->getCount() > 0) { $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop); } } } return true; }
/** * 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; }
/** * Init the default level data * * @param Server $server * @param string $name * @param string $path * @param string $provider Class that extends LevelProvider * * @throws \Throwable */ 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; if ($this->server->weatherEnabled and $this->folderName != $this->server->netherName or !$this->server->netherEnabled) { $this->weather = new Weather($this); } }