From 33bd66c1daf15ee806e63d5d259e0606d5a3056d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 15 May 2013 17:29:55 +0200 Subject: [PATCH] Added world teleporting --- src/API/BlockAPI.php | 2 +- src/API/ConsoleAPI.php | 6 ++---- src/API/ServerAPI.php | 2 +- src/Player.php | 12 ++++++------ src/material/item/generic/Painting.php | 4 ++-- src/world/Position.php | 7 +++++++ 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 6f00a7a59..b7b482a9c 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -321,7 +321,7 @@ class BlockAPI{ return false; } - if($item->isActivable === true and $item->onActivate($player, $block, $target, $face, $fx, $fy, $fz)){ + if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz)){ return $this->cancelAction($block, $player); } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 337c8778f..66f67a678 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -197,11 +197,9 @@ class ConsoleAPI{ $end = strpos($line, " "); if($end === false){ $end = strlen($line); - }else{ - ++$end; } - $cmd = strtolower(substr($line, 0, $end - 1)); - $params = substr($line, $end); + $cmd = strtolower(substr($line, 0, $end)); + $params = substr($line, $end + 1); if(isset($this->alias[$cmd])){ $this->run($this->alias[$cmd] . " " .$params, $issuer, $cmd); diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 193f3b1df..e8b9ca674 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -60,7 +60,7 @@ class ServerAPI{ $this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array( "server-name" => "Minecraft PE Server", "description" => "Server made using PocketMine-MP", - "motd" => "Welcome @username to this server!", + "motd" => "Welcome @player to this server!", "server-invisible" => false, "server-ip" => "0.0.0.0", "server-port" => 19132, diff --git a/src/Player.php b/src/Player.php index 0e6308c2d..7df038931 100644 --- a/src/Player.php +++ b/src/Player.php @@ -156,7 +156,7 @@ class Player{ )); } - $tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";"); + $tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";"); if($tiles !== false and $tiles !== true){ while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){ $this->server->api->tileentity->spawnTo($tile["ID"], $this); @@ -511,8 +511,7 @@ class Player{ } } } - $this->dataPacket(MC_CHAT, array( - + $this->dataPacket(MC_CHAT, array( "message" => $m, )); } @@ -579,6 +578,7 @@ class Player{ if($pos instanceof Position and $pos->level !== $this->level){ $this->level = $pos->level; $this->chunksLoaded = array(); + $terrain = true; } $this->lastCorrect = $pos; $this->entity->fallY = false; @@ -899,7 +899,7 @@ class Player{ $this->evid[] = $this->server->event("block.change", array($this, "eventHandler")); $this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler")); $this->server->schedule(40, array($this, "measureLag"), array(), true); - console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")"); + console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".$this->entity->level->getName().", ".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")"); break; case MC_READY: if($this->loggedIn === false){ @@ -986,7 +986,7 @@ class Player{ if($this->spawned === false){ break; } - if($this->blocked === true or Utils::distance($this->entity->position, $data) > 8){ + if($this->blocked === true or $this->entity->distance(new Vector3($data["x"], $data["y"], $data["z"])) > 8){ break; } $this->server->api->block->playerBlockBreak($this, new Vector3($data["x"], $data["y"], $data["z"])); @@ -1002,7 +1002,7 @@ class Player{ if($this->spawned === false){ break; } - if($this->gamemode !== VIEW and $this->blocked === false and isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){ + if($this->gamemode !== VIEW and $this->blocked === false and isset($this->server->entities[$data["target"]]) and $this->entity->distance($this->server->entities[$data["target"]]) <= 8){ $target = $this->server->api->entity->get($data["target"]); $data["targetentity"] = $target; $data["entity"] = $this->entity; diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index 3b00813e1..5bfc1eddf 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -78,8 +78,8 @@ class PaintingItem extends Item{ "yaw" => $faces[$face] * 90, "Motive" => $motive[0], ); - $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PAINTING, $data); - $server->api->entity->spawnToAll($this->level, $e->eid); + $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); + $server->api->entity->spawnToAll($level, $e->eid); if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($this->getID(), $this->getMetadata(), 1); } diff --git a/src/world/Position.php b/src/world/Position.php index 9a6e26718..3f73b0ae4 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -32,6 +32,13 @@ class Position extends Vector3{ parent::__construct($x, $y, $z); $this->level = $level; } + + public function distance($x = 0, $y = 0, $z = 0){ + if($x instanceof Position and $x->level !== $this->level){ + return PHP_INT_MAX; + } + return parent::distance($x, $y, $z); + } public function __toString(){ return "Position(level=".$this->level->getName().",x=".$this->x.",y=".$this->y.",z=".$this->z.")";