public function setHealth($amount) { $wasAlive = $this->isAlive(); parent::setHealth($amount); if ($this->isAlive() and !$wasAlive) { $pk = new EntityEventPacket(); $pk->eid = $this->getId(); $pk->event = EntityEventPacket::RESPAWN; Server::broadcastPacket($this->hasSpawned, $pk); } }
protected function processLogin() { if (!$this->server->isWhitelisted(strtolower($this->getName()))) { $this->close($this->getLeaveMessage(), "§cThis server is whitelisted. Contact the administrator to join."); return; } elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) { $this->close($this->getLeaveMessage(), "§cError while connecting to server. §l§4You are banned!"); return; } if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) { $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); } if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) { $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); } foreach ($this->server->getOnlinePlayers() as $p) { if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) { if ($p->kick("§4§lDisconnected,§r§b A User with your same MCPE Username is already logged in!") === false) { $this->close($this->getLeaveMessage(), "§4§lDisconnected,§r§b A User with your same MCPE Username is already logged in!"); return; } } elseif ($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())) { if ($p->kick("logged in from another location") === false) { $this->close($this->getLeaveMessage(), "§4§lDisconnected,§r§b A User with your same MCPE Username is already logged in!n"); return; } } } $nbt = $this->server->getOfflinePlayerData($this->username); $alive = true; if (!isset($nbt->NameTag)) { $nbt->NameTag = new String("NameTag", $this->username); } else { $nbt["NameTag"] = $this->username; } if (!isset($nbt->Hunger) or !isset($nbt->ExpCurrent) or !isset($nbt->ExpLevel) or !isset($nbt->Health) or !isset($nbt->MaxHealth)) { $nbt->Hunger = new Short("Hunger", 20); $nbt->ExpCurrent = new Long("ExpCurrent", 0); $nbt->ExpLevel = new Long("ExpLevel", 0); $nbt->Health = new Short("Health", 20); $nbt->MaxHealth = new Short("MaxHealth", 20); } $this->setFood($nbt["Hunger"]); $this->setMaxHealth($nbt["MaxHealth"]); if ($nbt["Health"] <= 0) { $alive = false; Entity::setHealth(20); } else { Entity::setHealth($nbt["Health"]); } $this->expcurrent = $nbt["ExpCurrent"] > 0 ? $nbt["ExpCurrent"] : 0; $this->explevel = $nbt["ExpLevel"] >= 0 ? $nbt["ExpLevel"] : 0; $this->gamemode = $nbt["playerGameType"] & 0x3; if ($this->server->getForceGamemode()) { $this->gamemode = $this->server->getGamemode(); $nbt->playerGameType = new Int("playerGameType", $this->gamemode); } $this->allowFlight = $this->isCreative(); if (($level = $this->server->getLevelByName($nbt["Level"])) === null or !$alive) { $this->setLevel($this->server->getDefaultLevel()); $nbt["Level"] = $this->level->getName(); $nbt["Pos"][0] = $this->level->getSpawnLocation()->x; $nbt["Pos"][1] = $this->level->getSpawnLocation()->y; $nbt["Pos"][2] = $this->level->getSpawnLocation()->z; } else { $this->setLevel($level); } if (!$nbt instanceof Compound) { $this->close($this->getLeaveMessage(), "Invalid data"); return; } $this->achievements = []; /** @var Byte $achievement */ foreach ($nbt->Achievements as $achievement) { $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false; } $nbt->lastPlayed = new Long("lastPlayed", floor(microtime(true) * 1000)); if ($this->server->getAutoSave()) { $this->server->saveOfflinePlayerData($this->username, $nbt, true); } parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt); $this->loggedIn = true; $this->server->addOnlinePlayer($this); $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); if ($ev->isCancelled()) { $this->close($this->getLeaveMessage(), $ev->getKickMessage()); return; } if ($this->isCreative()) { $this->inventory->setHeldItemSlot(0); } else { $this->inventory->setHeldItemSlot($this->inventory->getHotbarSlotIndex(0)); } $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::LOGIN_SUCCESS; $this->dataPacket($pk); if ($this->spawnPosition === null and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level) { $this->spawnPosition = new Position($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level); } $spawnPosition = $this->getSpawn(); $pk = new StartGamePacket(); $pk->seed = -1; $pk->dimension = 0; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->spawnX = (int) $spawnPosition->x; $pk->spawnY = (int) $spawnPosition->y; $pk->spawnZ = (int) $spawnPosition->z; $pk->generator = 1; // 0 old, 1 infinite, 2 flat $pk->gamemode = $this->gamemode & 0x1; $pk->eid = 0; // Always use EntityID as zero for the actual player $this->dataPacket($pk); $pk = new SetTimePacket(); $pk->time = $this->level->getTime(); $pk->started = $this->level->stopTime == false; $this->dataPacket($pk); $pk = new SetSpawnPositionPacket(); $pk->x = (int) $spawnPosition->x; $pk->y = (int) $spawnPosition->y; $pk->z = (int) $spawnPosition->z; $this->dataPacket($pk); $this->getAttribute()->sendAll(); $pk = new SetDifficultyPacket(); $pk->difficulty = $this->server->getDifficulty(); $this->dataPacket($pk); $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("BukkitPE.player.logIn", [TextFormat::AQUA . $this->username . TextFormat::WHITE, $this->ip, $this->port, $this->id, $this->level->getName(), round($this->x, 4), round($this->y, 4), round($this->z, 4)])); if ($this->isOp()) { $this->setRemoveFormat(false); } if ($this->gamemode === Player::SPECTATOR) { $pk = new ContainerSetContentPacket(); $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE; $this->dataPacket($pk); } else { $pk = new ContainerSetContentPacket(); $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE; $pk->slots = Item::getCreativeItems(); $this->dataPacket($pk); } $this->forceMovement = $this->teleportPosition = $this->getPosition(); $this->server->onPlayerLogin($this); }