From 4d0b184ca46e098df6dbe89b87d69a1479e5438e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 10 Jul 2014 12:35:19 +0200 Subject: [PATCH] Fixed #1591, handle player disconnect and level change killing --- src/pocketmine/Player.php | 14 ++++++++------ src/pocketmine/entity/Entity.php | 7 +++++-- src/pocketmine/level/Level.php | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2026d655f..5aeca85e2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -616,8 +616,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - //TODO - //$this->heal($this->data->get("health"), "spawn", true); $this->spawned = true; $this->sendSettings(); @@ -1231,6 +1229,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->spawnPosition = new Position($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level); } + $this->dead = false; $pk = new StartGamePacket; $pk->seed = $this->getLevel()->getSeed(); $pk->x = $this->x; @@ -1257,6 +1256,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new SetHealthPacket(); $pk->health = $this->getHealth(); $this->dataPacket($pk); + if($this->getHealth() <= 0){ + $this->dead = true; + } $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->getLevel()->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")"); @@ -1703,9 +1705,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ Server::broadcastPacket($this->getViewers(), $pk); break; case ProtocolInfo::RESPAWN_PACKET: - if($this->spawned === false or $this->dead !== true){ + if($this->spawned === false or $this->dead === false){ break; } + $this->craftingType = 0; $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->spawnPosition)); @@ -1713,6 +1716,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->teleport($ev->getRespawnPosition()); //$this->entity->fire = 0; //$this->entity->air = 300; + $this->setHealth(20); $this->dead = false; //$this->entity->updateMetadata(); @@ -2102,8 +2106,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->namedtag["playerGameType"] = $this->gamemode; $this->namedtag["lastPlayed"] = floor(microtime(true) * 1000); - //$this->data->set("health", $this->getHealth()); - if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){ $this->server->saveOfflinePlayerData($this->username, $this->namedtag); } @@ -2119,7 +2121,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } public function kill(){ - if($this->dead or $this->spawned === false){ + if($this->dead === true or $this->spawned === false){ return; } parent::kill(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 29c0ee3b2..5fdb4e729 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -425,7 +425,10 @@ abstract class Entity extends Position implements Metadatable{ } if($this->y < -64){ - $this->kill(); + $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10)); + if(!$ev->isCancelled()){ + $this->attack($ev->getFinalDamage(), $ev); + } } if($this->fireTicks > 0){ @@ -960,8 +963,8 @@ abstract class Entity extends Position implements Metadatable{ if($this->dead){ return; } - $this->setHealth(0); $this->dead = true; + $this->setHealth(0); $this->scheduleUpdate(); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 2c6399c56..bce55d5ed 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1389,10 +1389,12 @@ class Level implements ChunkManager, Metadatable{ if($entity->getLevel() !== $this){ throw new \RuntimeException("Invalid Entity level"); } - $entity->kill(); + if($entity instanceof Player){ unset($this->players[$entity->getID()]); //$this->everyoneSleeping(); + }else{ + $entity->kill(); } if($this->isChunkLoaded($entity->chunkX, $entity->chunkZ)){