From 38950969dd9167a2ea3b3f2e7d2d6ed83324cd01 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 18 Apr 2013 22:34:12 +0200 Subject: [PATCH] Added Player::setSpawn(Vector3 $pos) method --- src/API/PlayerAPI.php | 5 +++++ src/Player.php | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 03aec977..8611198a 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -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, diff --git a/src/Player.php b/src/Player.php index c6ee0baf..dbca38ba 100644 --- a/src/Player.php +++ b/src/Player.php @@ -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){