本文整理汇总了PHP中pocketmine\entity\Entity::setHealth方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::setHealth方法的具体用法?PHP Entity::setHealth怎么用?PHP Entity::setHealth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\entity\Entity
的用法示例。
在下文中一共展示了Entity::setHealth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHealth
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);
}
}
示例2: setHealth
public function setHealth($amount)
{
$wasAlive = !$this->dead;
parent::setHealth($amount);
if (!$this->dead and !$wasAlive) {
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::RESPAWN;
Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
}
示例3: setHealth
public function setHealth($amount)
{
$wasAlive = $this->isAlive();
parent::setHealth($amount);
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth());
if ($this->isAlive() and !$wasAlive) {
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::RESPAWN;
Server::broadcastPacket($this->hasSpawned, $pk);
}
}
示例4: processLogin
protected function processLogin()
{
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close($this->getLeaveMessage(), "Server is white-listed");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress()) or $this->server->getCIDBans()->isBanned($this->randomClientId)) {
$this->close($this->getLeaveMessage(), "You 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("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
} elseif ($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())) {
if ($p->kick("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
$nbt->NameTag = new StringTag("NameTag", $this->username);
} else {
$nbt["NameTag"] = $this->username;
}
if (!isset($nbt->Hunger) or !isset($nbt->Experience) or !isset($nbt->ExpLevel) or !isset($nbt->Health) or !isset($nbt->MaxHealth)) {
$nbt->Hunger = new ShortTag("Hunger", 20);
$nbt->Experience = new LongTag("Experience", 0);
$nbt->ExpLevel = new LongTag("ExpLevel", 0);
$nbt->Health = new ShortTag("Health", 20);
$nbt->MaxHealth = new ShortTag("MaxHealth", 20);
}
$this->food = $nbt["Hunger"];
$this->setMaxHealth($nbt["MaxHealth"]);
Entity::setHealth($nbt["Health"] <= 0 ? 20 : $nbt["Health"]);
$this->experience = $nbt["Experience"] > 0 ? $nbt["Experience"] : 0;
$this->explevel = $nbt["ExpLevel"] >= 0 ? $nbt["ExpLevel"] : 0;
$this->calcExpLevel();
$this->gamemode = $nbt["playerGameType"] & 0x3;
if ($this->server->getForceGamemode()) {
$this->gamemode = $this->server->getGamemode();
$nbt->playerGameType = new IntTag("playerGameType", $this->gamemode);
}
$this->allowFlight = $this->isCreative();
if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
$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 CompoundTag) {
$this->close($this->getLeaveMessage(), "Invalid data");
return;
}
$this->achievements = [];
/** @var ByteTag $achievement */
foreach ($nbt->Achievements as $achievement) {
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
}
$nbt->lastPlayed = new LongTag("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 = ChangeDimensionPacket::DIMENSION_NORMAL;
if ($this->server->netherEnabled) {
if ($this->getLevel() == $this->server->netherLevel) {
//.........这里部分代码省略.........
示例5: processLogin
protected function processLogin()
{
if ($this->isFirstTimeLogin) {
parent::processLogin();
} else {
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close($this->getLeaveMessage(), "Server is white-listed");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress()) or $this->server->getCIDBans()->isBanned($this->randomClientId)) {
$this->close($this->getLeaveMessage(), TextFormat::RED . "You 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("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
} elseif ($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())) {
if ($p->kick("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
$this->playedBefore = $nbt["lastPlayed"] - $nbt["firstPlayed"] > 1;
if (!isset($nbt->NameTag)) {
$nbt->NameTag = new StringTag("NameTag", $this->username);
} else {
$nbt["NameTag"] = $this->username;
}
if (!isset($nbt->Hunger) or !isset($nbt->Health) or !isset($nbt->MaxHealth)) {
$nbt->Hunger = new ShortTag("Hunger", 20);
$nbt->Health = new ShortTag("Health", 20);
$nbt->MaxHealth = new ShortTag("MaxHealth", 20);
}
$this->food = $nbt["Hunger"];
$this->setMaxHealth($nbt["MaxHealth"]);
Entity::setHealth($nbt["Health"] <= 0 ? 20 : $nbt["Health"]);
$this->gamemode = $nbt["playerGameType"] & 0x3;
if ($this->server->getForceGamemode()) {
$this->gamemode = $this->server->getGamemode();
$nbt->playerGameType = new IntTag("playerGameType", $this->gamemode);
}
$this->allowFlight = $this->isCreative();
if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
$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 CompoundTag) {
$this->close($this->getLeaveMessage(), "Invalid data");
return;
}
$this->achievements = [];
/** @var ByteTag $achievement */
foreach ($nbt->Achievements as $achievement) {
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
}
$nbt->lastPlayed = new LongTag("lastPlayed", floor(microtime(true) * 1000));
if ($this->server->getAutoSave()) {
$this->server->saveOfflinePlayerData($this->username, $nbt, true);
}
Entity::__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));
}
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 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);
//.........这里部分代码省略.........
示例6: processLogin
protected function processLogin()
{
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close($this->getLeaveMessage(), "Server is white-listed");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress()) or $this->server->getCIDBans()->isBanned($this->randomClientId)) {
$this->close($this->getLeaveMessage(), TextFormat::RED . "You 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("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
} elseif ($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())) {
if ($p->kick("logged in from another location") === false) {
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
}
}
$this->setNameTag($this->getDisplayName());
$nbt = $this->server->getOfflinePlayerData($this->username);
$this->playedBefore = $nbt["lastPlayed"] - $nbt["firstPlayed"] > 1;
if (!isset($nbt->NameTag)) {
$nbt->NameTag = new StringTag("NameTag", $this->username);
} else {
$nbt["NameTag"] = $this->username;
}
if (!isset($nbt->Hunger) or !isset($nbt->Health) or !isset($nbt->MaxHealth)) {
$nbt->Hunger = new ShortTag("Hunger", 20);
$nbt->Health = new ShortTag("Health", 20);
$nbt->MaxHealth = new ShortTag("MaxHealth", 20);
}
$this->food = $nbt["Hunger"];
$this->setMaxHealth($nbt["MaxHealth"]);
Entity::setHealth($nbt["Health"] <= 0 ? 20 : $nbt["Health"]);
$this->gamemode = $nbt["playerGameType"] & 0x3;
if ($this->server->getForceGamemode()) {
$this->gamemode = $this->server->getGamemode();
$nbt->playerGameType = new IntTag("playerGameType", $this->gamemode);
}
$this->allowFlight = $this->isCreative();
if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
$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 CompoundTag) {
$this->close($this->getLeaveMessage(), "Invalid data");
return;
}
$this->achievements = [];
/** @var ByteTag $achievement */
foreach ($nbt->Achievements as $achievement) {
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
}
$nbt->lastPlayed = new LongTag("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->isConnected()) {
return;
}
$this->dataPacket(new ResourcePacksInfoPacket());
if (!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level) {
$this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
}
$spawnPosition = $this->getSpawn();
$pk = new StartGamePacket();
$pk->entityUniqueId = 0;
$pk->entityRuntimeId = 0;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->seed = -1;
$pk->dimension = $this->level->getDimension();
$pk->gamemode = $this->gamemode & 0x1;
$pk->difficulty = $this->server->getDifficulty();
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
//.........这里部分代码省略.........