Fixed #1591, handle player disconnect and level change killing

This commit is contained in:
Shoghi Cervantes 2014-07-10 12:35:19 +02:00
parent 589fde27c0
commit 4d0b184ca4
3 changed files with 16 additions and 9 deletions

View File

@ -616,8 +616,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return; return;
} }
//TODO
//$this->heal($this->data->get("health"), "spawn", true);
$this->spawned = true; $this->spawned = true;
$this->sendSettings(); $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->spawnPosition = new Position($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
} }
$this->dead = false;
$pk = new StartGamePacket; $pk = new StartGamePacket;
$pk->seed = $this->getLevel()->getSeed(); $pk->seed = $this->getLevel()->getSeed();
$pk->x = $this->x; $pk->x = $this->x;
@ -1257,6 +1256,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk = new SetHealthPacket(); $pk = new SetHealthPacket();
$pk->health = $this->getHealth(); $pk->health = $this->getHealth();
$this->dataPacket($pk); $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) . ")"); $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); Server::broadcastPacket($this->getViewers(), $pk);
break; break;
case ProtocolInfo::RESPAWN_PACKET: case ProtocolInfo::RESPAWN_PACKET:
if($this->spawned === false or $this->dead !== true){ if($this->spawned === false or $this->dead === false){
break; break;
} }
$this->craftingType = 0; $this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->spawnPosition)); $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->teleport($ev->getRespawnPosition());
//$this->entity->fire = 0; //$this->entity->fire = 0;
//$this->entity->air = 300; //$this->entity->air = 300;
$this->setHealth(20); $this->setHealth(20);
$this->dead = false; $this->dead = false;
//$this->entity->updateMetadata(); //$this->entity->updateMetadata();
@ -2102,8 +2106,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->namedtag["playerGameType"] = $this->gamemode; $this->namedtag["playerGameType"] = $this->gamemode;
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000); $this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
//$this->data->set("health", $this->getHealth());
if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){ if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag); $this->server->saveOfflinePlayerData($this->username, $this->namedtag);
} }
@ -2119,7 +2121,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
public function kill(){ public function kill(){
if($this->dead or $this->spawned === false){ if($this->dead === true or $this->spawned === false){
return; return;
} }
parent::kill(); parent::kill();

View File

@ -425,7 +425,10 @@ abstract class Entity extends Position implements Metadatable{
} }
if($this->y < -64){ 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){ if($this->fireTicks > 0){
@ -960,8 +963,8 @@ abstract class Entity extends Position implements Metadatable{
if($this->dead){ if($this->dead){
return; return;
} }
$this->setHealth(0);
$this->dead = true; $this->dead = true;
$this->setHealth(0);
$this->scheduleUpdate(); $this->scheduleUpdate();
} }

View File

@ -1389,10 +1389,12 @@ class Level implements ChunkManager, Metadatable{
if($entity->getLevel() !== $this){ if($entity->getLevel() !== $this){
throw new \RuntimeException("Invalid Entity level"); throw new \RuntimeException("Invalid Entity level");
} }
$entity->kill();
if($entity instanceof Player){ if($entity instanceof Player){
unset($this->players[$entity->getID()]); unset($this->players[$entity->getID()]);
//$this->everyoneSleeping(); //$this->everyoneSleeping();
}else{
$entity->kill();
} }
if($this->isChunkLoaded($entity->chunkX, $entity->chunkZ)){ if($this->isChunkLoaded($entity->chunkX, $entity->chunkZ)){