Added /spawn [world] [player]

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-15 19:31:53 +02:00
parent 838e08b33b
commit bcbc65ed5e
3 changed files with 31 additions and 6 deletions

View File

@ -199,7 +199,7 @@ class ConsoleAPI{
$end = strlen($line);
}
$cmd = strtolower(substr($line, 0, $end));
$params = substr($line, $end + 1);
$params = (string) substr($line, $end + 1);
if(isset($this->alias[$cmd])){
$this->run($this->alias[$cmd] . " " .$params, $issuer, $cmd);
@ -249,8 +249,10 @@ class ConsoleAPI{
}
}
}
$params = explode(" ", $params);
if(count($params) === 1 and $params[0] === ""){
$params = array();
}
if($this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false
or $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false){

View File

@ -39,6 +39,7 @@ class PlayerAPI{
$this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
$this->server->api->console->register("tppos", "[target player] <x> <y> <z>", array($this, "commandHandler"));
$this->server->api->console->register("tp", "[target player] <destination player>", array($this, "commandHandler"));
$this->server->api->console->register("spawn", "[world]", array($this, "commandHandler"));
$this->server->api->console->register("lag", "", array($this, "commandHandler"));
$this->server->api->console->alias("suicide", "kill");
$this->server->api->ban->cmdWhitelist("list");
@ -114,6 +115,29 @@ class PlayerAPI{
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "spawn":
if(count($params) > 1){
$player = $this->server->api->player->get(array_pop($params));
}else{
$player = $issuer;
}
if(isset($params[0])){
$lv = $this->server->api->level->get(trim(implode(" ",$params)));
if($lv === false){
$output .= "Couldn't respawn.\n";
break;
}
$spawn = $lv->getSpawn();
}else{
$spawn = $this->server->api->level->getDefault()->getSpawn();
}
if(!($player instanceof Player)){
$output .= "Couldn't respawn.\n";
break;
}
$player->teleport($spawn);
break;
case "lag":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
@ -161,13 +185,13 @@ class PlayerAPI{
$name = $params[0];
$target = $params[1];
}else{
$output .= "Usage: /$cmd [player] <target>\n";
$output .= "Usage: /$cmd [target player] <destination player>\n";
break;
}
if($this->teleport($name, $target)){
$output .= "\"$name\" teleported to \"$target\"\n";
}else{
$output .= "Couldn't teleport\n";
$output .= "Couldn't teleport.\n";
}
break;
case "tppos":
@ -188,7 +212,7 @@ class PlayerAPI{
if($this->tppos($name, $x, $y, $z)){
$output .= "\"$name\" teleported to ($x, $y, $z)\n";
}else{
$output .= "Couldn't teleport\n";
$output .= "Couldn't teleport.\n";
}
break;
case "kill":

View File

@ -138,7 +138,6 @@ class Utils{
$m .= Utils::writeLInt($d["value"][$i]);
}
break;
}
}
$m .= "\x7f";