mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
Teleport command
This commit is contained in:
parent
c15f8cfda6
commit
cd6ce17c78
@ -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"]);
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user