Use the world spawn by default for players, fixes #1616

This commit is contained in:
Shoghi Cervantes 2014-07-11 12:45:43 +02:00
parent c16f45ce39
commit 4bd2f3aea8
2 changed files with 36 additions and 25 deletions

View File

@ -2,11 +2,11 @@
/* /*
* *
* ____ _ _ __ __ _ __ __ ____ * ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
@ -15,7 +15,7 @@
* *
* @author PocketMine Team * @author PocketMine Team
* @link http://www.pocketmine.net/ * @link http://www.pocketmine.net/
* *
* *
*/ */
@ -513,7 +513,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @return Position * @return Position
*/ */
public function getSpawn(){ public function getSpawn(){
return $this->spawnPosition; if($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level){
return $this->spawnPosition;
}else{
$level = $this->server->getDefaultLevel();
return $level->getSpawn();
}
} }
/** /**
@ -945,14 +950,16 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode); $this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
$spawnPosition = $this->getSpawn();
$pk = new StartGamePacket; $pk = new StartGamePacket;
$pk->seed = $this->getLevel()->getSeed(); $pk->seed = $this->getLevel()->getSeed();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
$pk->spawnX = (int) $this->spawnPosition->x; $pk->spawnX = (int) $spawnPosition->x;
$pk->spawnY = (int) $this->spawnPosition->y; $pk->spawnY = (int) $spawnPosition->y;
$pk->spawnZ = (int) $this->spawnPosition->z; $pk->spawnZ = (int) $spawnPosition->z;
$pk->generator = 1; //0 old, 1 infinite, 2 flat $pk->generator = 1; //0 old, 1 infinite, 2 flat
$pk->gamemode = $this->gamemode & 0x01; $pk->gamemode = $this->gamemode & 0x01;
$pk->eid = 0; //Always use EntityID as zero for the actual player $pk->eid = 0; //Always use EntityID as zero for the actual player
@ -1226,19 +1233,21 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->status = 0; $pk->status = 0;
$this->dataPacket($pk); $this->dataPacket($pk);
if(($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){ if(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); $this->spawnPosition = new Position($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
} }
$spawnPosition = $this->getSpawn();
$this->dead = false; $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;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
$pk->spawnX = (int) $this->spawnPosition->x; $pk->spawnX = (int) $spawnPosition->x;
$pk->spawnY = (int) $this->spawnPosition->y; $pk->spawnY = (int) $spawnPosition->y;
$pk->spawnZ = (int) $this->spawnPosition->z; $pk->spawnZ = (int) $spawnPosition->z;
$pk->generator = 1; //0 old, 1 infinite, 2 flat $pk->generator = 1; //0 old, 1 infinite, 2 flat
$pk->gamemode = $this->gamemode & 0x01; $pk->gamemode = $this->gamemode & 0x01;
$pk->eid = 0; //Always use EntityID as zero for the actual player $pk->eid = 0; //Always use EntityID as zero for the actual player
@ -1249,9 +1258,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = new SetSpawnPositionPacket; $pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x; $pk->x = (int) $spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y; $pk->y = (int) $spawnPosition->y;
$pk->z = (int) $this->spawnPosition->z; $pk->z = (int) $spawnPosition->z;
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = new SetHealthPacket(); $pk = new SetHealthPacket();
@ -2105,10 +2114,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
public function save(){ public function save(){
parent::saveNBT(); parent::saveNBT();
$this->namedtag["Level"] = $this->getLevel()->getName(); $this->namedtag["Level"] = $this->getLevel()->getName();
$this->namedtag["SpawnLevel"] = $this->getLevel()->getName(); if($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level){
$this->namedtag["SpawnX"] = (int) $this->spawnPosition->x; $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName();
$this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
}
foreach($this->achievements as $achievement => $status){ foreach($this->achievements as $achievement => $status){
$this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0); $this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0);

View File

@ -633,11 +633,11 @@ class Server{
new Double(2, $spawn->z) new Double(2, $spawn->z)
)), )),
new String("Level", $this->getDefaultLevel()->getName()), new String("Level", $this->getDefaultLevel()->getName()),
new String("SpawnLevel", $this->getDefaultLevel()->getName()), //new String("SpawnLevel", $this->getDefaultLevel()->getName()),
new Int("SpawnX", (int) $spawn->x), //new Int("SpawnX", (int) $spawn->x),
new Int("SpawnY", (int) $spawn->y), //new Int("SpawnY", (int) $spawn->y),
new Int("SpawnZ", (int) $spawn->z), //new Int("SpawnZ", (int) $spawn->z),
new Byte("SpawnForced", 1), //TODO //new Byte("SpawnForced", 1), //TODO
new Enum("Inventory", []), new Enum("Inventory", []),
new Compound("Achievements", []), new Compound("Achievements", []),
new Int("playerGameType", $this->getGamemode()), new Int("playerGameType", $this->getGamemode()),