From cd6ce17c78cc5404005c99efd688f70373240caf Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 12 Dec 2012 01:11:14 +0100 Subject: [PATCH] Teleport command --- classes/API/PlayerAPI.php | 38 ++++++++++++++++++++++++++++++++++++++ classes/Session.class.php | 20 ++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/classes/API/PlayerAPI.php b/classes/API/PlayerAPI.php index d247ec129..4483f7cd5 100644 --- a/classes/API/PlayerAPI.php +++ b/classes/API/PlayerAPI.php @@ -34,10 +34,34 @@ class PlayerAPI{ public function init(){ $this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler")); $this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler")); + $this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler")); + $this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler")); } public function commandHandler($cmd, $params){ switch($cmd){ + case "tp": + $name = array_shift($params); + $target = array_shift($params); + if($name == null or $target == null){ + console("[INFO] Usage: /tp "); + break; + } + $this->teleport($name, $target); + console("[INFO] \"$name\" teleported to \"$target\""); + break; + case "tppos": + $z = array_pop($params); + $y = array_pop($params); + $x = array_pop($params); + $name = implode(" ", $params); + if($name == null or $x === null or $y === null or $z === null){ + console("[INFO] Usage: /tp "); + break; + } + $this->tppos($name, $x, $y, $z); + console("[INFO] \"$name\" teleported to ($x, $y, $z)"); + break; case "kill": $player = $this->get(implode(" ", $params)); if($player !== false){ @@ -55,6 +79,20 @@ class PlayerAPI{ } } + public function teleport($name, $target){ + $target = $this->get($target); + if($target !== false){ + $this->tppos($name, $target->entity->position["x"], $target->entity->position["y"], $target->entity->position["z"]); + } + } + + public function tppos($name, $x, $y, $z){ + $player = $this->get($name); + if($player !== false){ + $this->server->trigger("onTeleport", array("eid" => $player->eid, "x" => $x, "y" => $y, "z" => $z)); + } + } + public function get($name){ $CID = $this->server->query("SELECT ip,port FROM players WHERE name = '".str_replace("'", "", $name)."';", true); $CID = $this->server->clientID($CID["ip"], $CID["port"]); diff --git a/classes/Session.class.php b/classes/Session.class.php index 3747f64d7..a6a2a10ef 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -91,6 +91,25 @@ class Session{ $this->server->trigger("onPlayerDeath", array("name" => $this->username, "cause" => $data["cause"])); } break; + case "onTeleport": + if($data["eid"] !== $this->eid){ + break; + } + $this->send(0x84, array( + $this->counter[0], + 0x00, + array( + "id" => MC_MOVE_PLAYER, + "eid" => $data["eid"], + "x" => $data["x"], + "y" => $data["y"], + "z" => $data["z"], + "yaw" => 0, + "pitch" => 0, + ), + )); + ++$this->counter[0]; + break; case "onEntityMove": if($data === $this->eid){ break; @@ -271,6 +290,7 @@ class Session{ $this->evid[] = array("onHealthChange", $this->server->event("onHealthChange", array($this, "eventHandler"))); $this->evid[] = array("onHealthRegeneration", $this->server->event("onHealthRegeneration", array($this, "eventHandler"))); $this->evid[] = array("onAnimate", $this->server->event("onAnimate", array($this, "eventHandler"))); + $this->evid[] = array("onTeleport", $this->server->event("onTeleport", array($this, "eventHandler"))); $this->send(0x84, array( $this->counter[0], 0x00,