Teleport command

This commit is contained in:
Shoghi Cervantes Pueyo
2012-12-12 01:11:14 +01:00
parent c15f8cfda6
commit cd6ce17c78
2 changed files with 58 additions and 0 deletions

View File

@ -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 <player> <target>");
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 <player> <x> <y> <z>");
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"]);