本文整理汇总了PHP中pocketmine\utils\Utils类的典型用法代码示例。如果您正苦于以下问题:PHP Utils类的具体用法?PHP Utils怎么用?PHP Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
public function check()
{
$d = Utils::getRealMemoryUsage();
$u = Utils::getMemoryUsage(true);
$usage = round($u[0] / 1024 / 1024, 2) . "/" . round($d[0] / 1024 / 1024, 2) . "/" . round($u[1] / 1024 / 1024, 2) . "/" . round($u[2] / 1024 / 1024, 2) . " MB @ " . Utils::getThreadCount() . " threads";
$serverStatus = serialize(["online" => count($this->server->getOnlinePlayers()), "max" => $this->server->getMaxPlayers(), "upload" => round($this->server->getNetwork()->getUpload() / 1024, 2), "download" => round($this->server->getNetwork()->getDownload() / 1024, 2), "tps" => $this->server->getTicksPerSecondAverage(), "load" => $this->server->getTickUsageAverage(), "usage" => $usage]);
for ($n = 0; $n < $this->threads; ++$n) {
if (!$this->workers[$n]->isTerminated()) {
$this->workers[$n]->serverStatus = $serverStatus;
}
if ($this->workers[$n]->isTerminated() === true) {
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
} elseif ($this->workers[$n]->isWaiting()) {
if ($this->workers[$n]->response !== "") {
$this->server->getLogger()->info($this->workers[$n]->response);
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
} else {
$response = new RemoteConsoleCommandSender();
$command = $this->workers[$n]->cmd;
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
if (!$ev->isCancelled()) {
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
}
$this->workers[$n]->response = $response->getMessage();
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
}
}
}
}
示例2: onRun
public function onRun()
{
$out = Utils::getURL($this->source);
if (is_string($out)) {
file_put_contents($this->dest, $out);
}
}
示例3: run
public function run()
{
if ($this->readline) {
readline_callback_handler_install("CS> ", [$this, "readline_callback"]);
$this->logger->setConsoleCallback("readline_redisplay");
}
while (!$this->shutdown) {
$r = [$this->stdin];
$w = null;
$e = null;
if (stream_select($r, $w, $e, 0, 200000) > 0) {
// PHP on Windows sucks
if (feof($this->stdin)) {
if (Utils::getOS() == "win") {
$this->stdin = fopen("php://stdin", "r");
if (!is_resource($this->stdin)) {
break;
}
} else {
break;
}
}
$this->readLine();
}
}
if ($this->readline) {
$this->logger->setConsoleCallback(null);
readline_callback_handler_remove();
}
}
示例4: onRun
public function onRun()
{
$ch = curl_init("https://api.mojang.com/profiles/minecraft");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([$this->username]));
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP", "Content-Type: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$ret = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!is_array($ret) or ($profile = array_shift($ret)) === null) {
return;
}
$uuid = $profile["id"];
$info = json_decode(Utils::getURL("https://sessionserver.mojang.com/session/minecraft/profile/{$uuid}", 3), true);
if (!is_array($info)) {
return;
}
$this->setResult($info);
}
示例5: tick
private function tick()
{
while (is_string($text = $this->next())) {
echo "Sending message {$text}\r\n";
Utils::getURL(self::WEBHOOK . urlencode($text));
}
}
示例6: onRun
public function onRun()
{
try {
Utils::postURL($this->endpoint, $this->data, 5, ["Content-Type: application/json", "Content-Length: " . strlen($this->data)]);
} catch (\Exception $e) {
}
}
示例7: onRun
public function onRun()
{
if ($this->build === "beta") {
$url = "https://api.github.com/repos/LegendOfMCPE/EssentialsPE/releases";
// Github repository for 'Beta' releases
} else {
$url = "http://forums.pocketmine.net/api.php?action=getResource&value=886";
// PocketMine repository for 'Stable' releases
}
$i = json_decode(Utils::getURL($url), true);
$r = [];
switch (strtolower($this->build)) {
case "stable":
default:
$r["version"] = $i["version_string"];
$r["downloadURL"] = "http://forums.pocketmine.net/plugins/essentialspe.886/download?version=" . $i["current_version_id"];
break;
case "beta":
$i = $i[0];
// Grab the latest version from Github releases... Doesn't matter if it's Beta or Stable :3
$r["version"] = substr($i["name"], 13);
$r["downloadURL"] = $i["assets"][0]["browser_download_url"];
break;
}
$this->setResult($r);
}
示例8: checkUpdate
public function checkUpdate()
{
$this->getPlugin()->getServer()->getPluginManager()->callEvent($event = new UpdateCheckingEvent($this->getPlugin(), $this->channel));
if ($event->isCancelled()) {
return false;
}
if ($this->channel == "beta") {
$address = "https://api.github.com/repos/cybercube-hk/jail/releases";
} else {
$this->plugin->getLogger()->alert("[UPDATER] INVALID CHANNEL!");
return false;
}
$i = json_decode(Utils::getURL($address), true);
if ($this->channel == "beta") {
$i = $i[0];
$this->newversion = substr($i["name"], 6);
$this->dlurl = $i["assets"][0]["browser_download_url"];
}
$plugin = $this->getPlugin();
if ($plugin::VERSION_STRING !== $this->newversion) {
$path = $this->plugin->getDataFolder() . "newest-version-download-link.txt";
echo "\n";
$this->plugin->getLogger()->info("Your version is too old or too new! The latest " . $this->channel . " version is: (version: " . $this->newversion . ")");
$this->plugin->getLogger()->info("Download url for the latest version: §e" . $this->dlurl . "");
$this->plugin->getLogger()->info("The link is being saved into: §bnewest-version-download-link.txt\n");
$txt = new Config($path, Config::ENUM);
$txt->set("Version " . $this->newversion . " -> " . $this->dlurl, true);
$txt->save();
return true;
}
echo "\n";
$this->plugin->getLogger()->info("No updates found! Your Jail version is up-to-date!\n");
return true;
}
示例9: __construct
public function __construct(WorldEditArt $main)
{
if (Utils::getOS() !== "win") {
throw new \RuntimeException("//wea-config is only for Windows.");
}
$this->main = $main;
parent::__construct("/wea-config", "Start WorldEditArt installer(will stop the server)", "/wea-config");
}
示例10: write
public function write()
{
$spawningPool = new SpawningPool($this->getServer(), Utils::getCoreCount());
$this->setPrivateVariableData($this->getServer()->getScheduler(), "asyncPool", $spawningPool);
foreach ($this->getServer()->getLevels() as $level) {
$level->registerGenerator();
}
}
示例11: onLogin
public function onLogin(PlayerPreLoginEvent $event)
{
$player = $event->getPlayer();
$addressInfo = json_decode(Utils::getURL(" http://freegeoip.net/json/" . $player->getAddress()), true);
if (!$addressInfo[country_code] == "KR") {
$event->setKickMessage("You are not Korean");
$event->setCanCelled();
}
}
示例12: execute
public function execute(CommandSender $sender, $currentAlias, array $args)
{
if (!$this->testPermission($sender)) {
return \true;
}
$mUsage = Utils::getMemoryUsage(\true);
$rUsage = Utils::getRealMemoryUsage(\true);
$server = $sender->getServer();
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "服务器状态" . TextFormat::GREEN . " ----");
$sender->sendMessage(TextFormat::GOLD . "服务器人数: " . TextFormat::GREEN . \count($sender->getServer()->getOnlinePlayers()) . "/" . $sender->getServer()->getMaxPlayers());
$time = \microtime(\true) - \pocketmine\START_TIME;
$seconds = \floor($time % 60);
$minutes = \null;
$hours = \null;
$days = \null;
if ($time >= 60) {
$minutes = \floor($time % 3600 / 60);
if ($time >= 3600) {
$hours = \floor($time % (3600 * 24) / 3600);
if ($time >= 3600 * 24) {
$days = \floor($time / (3600 * 24));
}
}
}
$uptime = ($minutes !== \null ? ($hours !== \null ? ($days !== \null ? "{$days} 天 " : "") . "{$hours} 小时 " : "") . "{$minutes} 分 " : "") . "{$seconds} 秒";
$sender->sendMessage(TextFormat::GOLD . "运行时间: " . TextFormat::RED . $uptime);
$tpsColor = TextFormat::GREEN;
if ($server->getTicksPerSecondAverage() < 10) {
$tpsColor = TextFormat::GOLD;
} elseif ($server->getTicksPerSecondAverage() < 1) {
$tpsColor = TextFormat::RED;
}
$tpsColour = TextFormat::GREEN;
if ($server->getTicksPerSecond() < 10) {
$tpsColour = TextFormat::GOLD;
} elseif ($server->getTicksPerSecond() < 1) {
$tpsColour = TextFormat::RED;
}
$sender->sendMessage(TextFormat::GOLD . "平均TPS: " . $tpsColor . $server->getTicksPerSecondAverage() . " (" . $server->getTickUsageAverage() . "%)");
$sender->sendMessage(TextFormat::GOLD . "瞬时TPS: " . $tpsColour . $server->getTicksPerSecond() . " (" . $server->getTickUsage() . "%)");
$sender->sendMessage(TextFormat::GOLD . "网络上传: " . TextFormat::RED . \round($server->getNetwork()->getUpload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "网络下载: " . TextFormat::RED . \round($server->getNetwork()->getDownload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "线程总数: " . TextFormat::RED . Utils::getThreadCount());
$sender->sendMessage(TextFormat::GOLD . "主线程内存: " . TextFormat::RED . \number_format(\round($mUsage[0] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "总内存: " . TextFormat::RED . \number_format(\round($mUsage[1] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "总虚拟内存: " . TextFormat::RED . number_format(round($mUsage[2] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "堆栈内存: " . TextFormat::RED . number_format(round($rUsage[0] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "系统最大内存: " . TextFormat::RED . \number_format(\round($mUsage[2] / 1024 / 1024, 2)) . " MB.");
if ($server->getProperty("memory.global-limit") > 0) {
$sender->sendMessage(TextFormat::GOLD . "核心全局最大内存: " . TextFormat::RED . \number_format(\round($server->getProperty("memory.global-limit"), 2)) . " MB.");
}
foreach ($server->getLevels() as $level) {
$sender->sendMessage(TextFormat::GOLD . "世界 \"" . $level->getFolderName() . "\"" . ($level->getFolderName() !== $level->getName() ? " (" . $level->getName() . ")" : "") . ": " . TextFormat::RED . \number_format(\count($level->getChunks())) . TextFormat::GREEN . " 区块, " . TextFormat::RED . \number_format(\count($level->getEntities())) . TextFormat::GREEN . " 实体, " . TextFormat::RED . \number_format(\count($level->getTiles())) . TextFormat::GREEN . " tiles. " . "时间 " . (($level->getTickRate() > 1 or $level->getTickRateTime() > 40) ? TextFormat::RED : TextFormat::YELLOW) . \round($level->getTickRateTime(), 2) . "毫秒" . ($level->getTickRate() > 1 ? " (tick rate " . $level->getTickRate() . ")" : ""));
}
return \true;
}
示例13: execute
public function execute(CommandSender $sender, $currentAlias, array $args)
{
if (!$this->testPermission($sender)) {
return true;
}
$rUsage = Utils::getRealMemoryUsage();
$mUsage = Utils::getMemoryUsage(true);
$server = $sender->getServer();
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "%pocketmine.command.status.title" . TextFormat::GREEN . " ----");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.player " . TextFormat::GREEN . count($sender->getServer()->getOnlinePlayers()) . "/" . $sender->getServer()->getMaxPlayers());
$time = microtime(true) - \pocketmine\START_TIME;
$seconds = floor($time % 60);
$minutes = null;
$hours = null;
$days = null;
if ($time >= 60) {
$minutes = floor($time % 3600 / 60);
if ($time >= 3600) {
$hours = floor($time % (3600 * 24) / 3600);
if ($time >= 3600 * 24) {
$days = floor($time / (3600 * 24));
}
}
}
$uptime = ($minutes !== null ? ($hours !== null ? ($days !== null ? "{$days} %pocketmine.command.status.days " : "") . "{$hours} %pocketmine.command.status.hours " : "") . "{$minutes} %pocketmine.command.status.minutes " : "") . "{$seconds} %pocketmine.command.status.seconds";
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.uptime " . TextFormat::RED . $uptime);
$tpsColor = TextFormat::GREEN;
if ($server->getTicksPerSecondAverage() < 10) {
$tpsColor = TextFormat::GOLD;
} elseif ($server->getTicksPerSecondAverage() < 1) {
$tpsColor = TextFormat::RED;
}
$tpsColour = TextFormat::GREEN;
if ($server->getTicksPerSecond() < 10) {
$tpsColour = TextFormat::GOLD;
} elseif ($server->getTicksPerSecond() < 1) {
$tpsColour = TextFormat::RED;
}
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.AverageTPS " . $tpsColor . $server->getTicksPerSecondAverage() . " (" . $server->getTickUsageAverage() . "%)");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.CurrentTPS " . $tpsColour . $server->getTicksPerSecond() . " (" . $server->getTickUsage() . "%)");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Networkupload " . TextFormat::RED . round($server->getNetwork()->getUpload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Networkdownload " . TextFormat::RED . round($server->getNetwork()->getDownload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Threadcount " . TextFormat::RED . Utils::getThreadCount());
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Mainmemory " . TextFormat::RED . number_format(round($mUsage[0] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Totalmemory " . TextFormat::RED . number_format(round($mUsage[1] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Totalvirtualmemory " . TextFormat::RED . number_format(round($mUsage[2] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Heapmemory " . TextFormat::RED . number_format(round($rUsage[0] / 1024 / 1024, 2)) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Maxmemorysystem " . TextFormat::RED . number_format(round($mUsage[2] / 1024 / 1024, 2)) . " MB.");
if ($server->getProperty("memory.global-limit") > 0) {
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.Maxmemorymanager " . TextFormat::RED . number_format(round($server->getProperty("memory.global-limit"), 2)) . " MB.");
}
foreach ($server->getLevels() as $level) {
$sender->sendMessage(TextFormat::GOLD . "%pocketmine.command.status.World \"" . $level->getFolderName() . "\"" . ($level->getFolderName() !== $level->getName() ? " (" . $level->getName() . ")" : "") . ": " . TextFormat::RED . number_format(count($level->getChunks())) . TextFormat::GREEN . " %pocketmine.command.status.chunks " . TextFormat::RED . number_format(count($level->getEntities())) . TextFormat::GREEN . " %pocketmine.command.status.entities " . TextFormat::RED . number_format(count($level->getTiles())) . TextFormat::GREEN . " %pocketmine.command.status.tiles " . "%pocketmine.command.status.Time " . (($level->getTickRate() > 1 or $level->getTickRateTime() > 40) ? TextFormat::RED : TextFormat::YELLOW) . round($level->getTickRateTime(), 2) . "%pocketmine.command.status.ms" . ($level->getTickRate() > 1 ? " (tick rate " . $level->getTickRate() . ")" : ""));
}
return true;
}
示例14: onRun
public function onRun()
{
$list = [];
foreach ($this->ip as $spl => $ip) {
$data = Utils::getURL("http://ip-api.com/json/" . $ip);
$data = json_decode($data, true);
$list[$spl] = $data["country"];
}
$this->setResult($list);
}
示例15: check
protected function check()
{
$response = Utils::getURL($this->endpoint . "?channel=" . $this->getChannel(), 4);
$response = json_decode($response, true);
if (!is_array($response)) {
return;
}
$this->updateInfo = ["version" => $response["version"], "api_version" => $response["api_version"], "build" => $response["build"], "date" => $response["date"], "details_url" => isset($response["details_url"]) ? $response["details_url"] : null, "download_url" => $response["download_url"]];
$this->checkUpdate();
}