Added Player::setSpawn(Vector3 $pos) method

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-18 22:34:12 +02:00
parent 9a4c3f8c9f
commit 38950969dd
2 changed files with 23 additions and 6 deletions

View File

@ -321,6 +321,11 @@ class PlayerAPI{
"y" => $this->server->spawn["y"],
"z" => $this->server->spawn["z"],
),
"spawn" => array(
"x" => $this->server->spawn["x"],
"y" => $this->server->spawn["y"],
"z" => $this->server->spawn["z"],
),
"inventory" => array_fill(0, 36, array(AIR, 0, 0)),
"armor" => array_fill(0, 4, array(AIR, 0, 0)),
"gamemode" => $this->server->gamemode,

View File

@ -61,6 +61,7 @@ class Player{
private $chunksLoaded = array();
private $chunksOrder = array();
private $lag = array(0, 0);
private $spawnPosition;
public $itemEnforcement;
public $lastCorrect;
@ -80,6 +81,7 @@ class Player{
$this->ip = $ip;
$this->port = $port;
$this->itemEnforcement = $this->server->api->getProperty("item-enforcement");
$this->spawnPosition = new Vector3($this->server->spawn["x"], $this->server->spawn["y"], $this->server->spawn["z"]);
$this->timeout = microtime(true) + 20;
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
$this->armor = array_fill(0, 4, array(AIR, 0, 0));
@ -91,6 +93,15 @@ class Player{
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
}
public function setSpawn(Vector3 $pos){
$this->spawnPosition = $pos;
$this->dataPacket(MC_SET_SPAWN_POSITION, array(
"x" => (int) $this->spawnPosition->x,
"y" => (int) $this->spawnPosition->y,
"z" => (int) $this->spawnPosition->z,
));
}
public function orderChunks(){
if(!($this->entity instanceof Entity)){
return false;
@ -190,6 +201,11 @@ class Player{
"y" => $this->entity->y,
"z" => $this->entity->z,
));
$this->data->set("spawn", array(
"x" => $this->spawnPosition->x,
"y" => $this->spawnPosition->y,
"z" => $this->spawnPosition->z,
));
$this->data->set("inventory", $this->inventory);
$this->data->set("armor", $this->armor);
$this->data->set("gamemode", $this->gamemode);
@ -865,11 +881,7 @@ class Player{
$this->server->schedule(50, array($this, "orderChunks"), array(), true);
$this->blocked = false;
$this->teleport(new Vector3($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"]));
$this->dataPacket(MC_SET_SPAWN_POSITION, array(
"x" => (int) $this->server->spawn["x"],
"y" => (int) $this->server->spawn["y"],
"z" => (int) $this->server->spawn["z"],
));
$this->setSpawn(new Vector3($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"]));
break;
case 2://Chunk loaded?
break;
@ -1035,7 +1047,7 @@ class Player{
$this->entity->setHealth(20, "respawn");
$this->entity->updateMetadata();
$this->sendInventory();
$this->teleport(new Vector3($this->server->spawn["x"], $this->server->spawn["y"], $this->server->spawn["z"]));
$this->teleport($this->spawnPosition);
break;
case MC_SET_HEALTH:
if($this->spawned === false){