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); }
public function __construct(FullChunk $chunk, Compound $nbt) { if ($chunk === null or $chunk->getProvider() === null) { throw new ChunkException("Invalid garbage Chunk given to Entity"); } $this->timings = Timings::getEntityTimings($this); if ($this->eyeHeight === null) { $this->eyeHeight = $this->height / 2 + 0.1; } $this->id = Entity::$entityCount++; $this->justCreated = true; $this->namedtag = $nbt; $this->chunk = $chunk; $this->setLevel($chunk->getProvider()->getLevel()); $this->server = $chunk->getProvider()->getLevel()->getServer(); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->setPositionAndRotation(new Vector3($this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1], true); $this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); if (!isset($this->namedtag->FallDistance)) { $this->namedtag->FallDistance = new Float("FallDistance", 0); } $this->fallDistance = $this->namedtag["FallDistance"]; if (!isset($this->namedtag->Fire)) { $this->namedtag->Fire = new Short("Fire", 0); } $this->fireTicks = $this->namedtag["Fire"]; if (!isset($this->namedtag->Air)) { $this->namedtag->Air = new Short("Air", 300); } $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]); if (!isset($this->namedtag->OnGround)) { $this->namedtag->OnGround = new Byte("OnGround", 0); } $this->onGround = $this->namedtag["OnGround"] > 0 ? true : false; if (!isset($this->namedtag->Invulnerable)) { $this->namedtag->Invulnerable = new Byte("Invulnerable", 0); } $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false; $this->chunk->addEntity($this); $this->level->addEntity($this); $this->initEntity(); $this->lastUpdate = $this->server->getTick(); $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this)); $this->checkBlockCollisionTicks = (int) $this->server->getAdvancedProperty("main.check-block-collision", 1); $this->scheduleUpdate(); }
/** * @param Vector3 $pos * @param int $delay */ public function scheduleUpdate(Vector3 $pos, $delay) { if (isset($this->updateQueueIndex[$index = PHP_INT_SIZE === 8 ? ($pos->x & 0xfffffff) << 35 | ($pos->y & 0x7f) << 28 | $pos->z & 0xfffffff : $pos->x . ":" . $pos->y . ":" . $pos->z]) and $this->updateQueueIndex[$index] <= $delay) { return; } $this->updateQueueIndex[$index] = $delay; $this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); }
/** * @param Vector3 $pos * @param int $delay */ public function scheduleUpdate(Vector3 $pos, $delay) { if (isset($this->updateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->updateQueueIndex[$index] <= $delay) { return; } $this->updateQueueIndex[$index] = $delay; $this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); }
/** * @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; }
public function __construct(FullChunk $chunk, CompoundTag $nbt) { assert($chunk !== null and $chunk->getProvider() !== null); $this->timings = Timings::getEntityTimings($this); $this->isPlayer = $this instanceof Player; $this->temporalVector = new Vector3(); if ($this->eyeHeight === null) { $this->eyeHeight = $this->height / 2 + 0.1; } $this->id = Entity::$entityCount++; $this->justCreated = true; $this->namedtag = $nbt; $this->chunk = $chunk; $this->setLevel($chunk->getProvider()->getLevel()); $this->server = $chunk->getProvider()->getLevel()->getServer(); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->setPositionAndRotation($this->temporalVector->setComponents($this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1]); $this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z)); if (!isset($this->namedtag->FallDistance)) { $this->namedtag->FallDistance = new FloatTag("FallDistance", 0); } $this->fallDistance = $this->namedtag["FallDistance"]; if (!isset($this->namedtag->Fire) || $this->namedtag["Fire"] > 32767) { $this->namedtag->Fire = new ShortTag("Fire", 0); } $this->fireTicks = $this->namedtag["Fire"]; if (!isset($this->namedtag->Air)) { $this->namedtag->Air = new ShortTag("Air", 300); } $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"], false); if (!isset($this->namedtag->OnGround)) { $this->namedtag->OnGround = new ByteTag("OnGround", 0); } $this->onGround = $this->namedtag["OnGround"] > 0 ? true : false; if (!isset($this->namedtag->Invulnerable)) { $this->namedtag->Invulnerable = new ByteTag("Invulnerable", 0); } $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false; $this->attributeMap = new AttributeMap(); $this->chunk->addEntity($this); $this->level->addEntity($this); $this->initEntity(); $this->lastUpdate = $this->server->getTick(); $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this)); $this->scheduleUpdate(); }
/** * @param Vector3 $pos * @param int $delay */ public function setRedstoneUpdate(Vector3 $pos, $delay, $type, $power) { if (!$this->getServer()->isAllowRedstoneCalculation()) { return; } 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()); }
/** * @param Vector3 $pos * @param int $delay */ public function setRedstoneUpdate(Vector3 $pos, $delay, $type, $power) { if ($this->server->getProperty("redstone.enable", true)) { $this->updateRedstoneQueueIndex[Level::blockHash($pos->x, $pos->y, $pos->z)][] = ['delay' => $delay, 'type' => $type, 'power' => $power]; $this->updateRedstoneQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); } return; }
/** * @param Vector3 $pos * @param int $delay */ public function setRedstoneUpdate(Vector3 $pos, $delay, $type, $power) { if ($this->server->getProperty("redstone.enable", true)) { $hash = Level::blockHash($pos->x, $pos->y, $pos->z); if (isset($this->updateRedstoneQueueIndex[$hash])) { if ($this->compareRedstone(\end($this->updateRedstoneQueueIndex[$hash]), ['type' => $type, 'power' => $power])) { return false; } } $this->updateRedstoneQueueIndex[$hash][] = ['delay' => $delay, 'type' => $type, 'power' => $power]; $this->updateRedstoneQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); } return; }