From 2b741a29130020ada256e5564c6024db6c5ec965 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Tue, 9 Apr 2013 18:44:13 +0200 Subject: [PATCH] Fixed crashes, added flying check --- src/API/BanAPI.php | 2 +- src/API/ServerAPI.php | 3 ++- src/Player.php | 4 ++-- src/world/Entity.php | 44 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index da54dfb2..8b6aed65 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -79,7 +79,7 @@ class BanAPI{ if(!$this->isOp($data["player"]->iusername)){ $t = new Vector2($data["target"]->x, $data["target"]->z); $s = new Vector2($this->server->spawn["x"], $this->server->spawn["z"]); - if($t->distance($s) <= $this->server->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){ + if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){ return false; } } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index d937c305..c57a195f 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -104,9 +104,10 @@ class ServerAPI{ "spawn-protection" => 16, "view-distance" => 7, "max-players" => 20, + "allow-flight" => false, "server-type" => "normal", "time-per-second" => 20, - "gamemode" => 1, + "gamemode" => CREATIVE, "pvp" => true, "difficulty" => 1, "generator" => "", diff --git a/src/Player.php b/src/Player.php index e5a6eaf4..0c961581 100644 --- a/src/Player.php +++ b/src/Player.php @@ -110,7 +110,7 @@ class Player{ public function getNextChunk($repeat = false){ $c = key($this->chunksOrder); $d = $this->chunksOrder[$c]; - if($c === null or $d > $this->server->getProperty("view-distance")){ + if($c === null or $d > $this->server->api->getProperty("view-distance")){ $this->server->schedule(50, array($this, "getNextChunk")); return false; } @@ -858,7 +858,7 @@ class Player{ $data["entity"] = $this->entity; if(!($target instanceof Entity)){ break; - }elseif($target->class === ENTITY_PLAYER and ($this->server->getProperty("pvp") == false or $this->server->difficulty <= 0 or $target->player->gamemode === CREATIVE)){ + }elseif($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or $target->player->gamemode === CREATIVE)){ break; }elseif($this->handle("player.interact", $data) !== false){ switch($this->equipment->getID()){ diff --git a/src/world/Entity.php b/src/world/Entity.php index 1dadfd99..9160057f 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -304,10 +304,27 @@ class Entity extends stdClass{ } if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER){ - $x = (int) round($this->x - 0.5); + $startX = ((int) round($this->x - 0.5)) - 1; $y = (int) round($this->y - 1); - $z = (int) round($this->z - 0.5); - $blockDown = $this->server->api->block->getBlock(new Vector3($x, $y, $z)); + $startZ = ((int) round($this->z - 0.5)) - 1; + $endX = $startX + 2; + $endZ = $startZ + 2; + $support = false; + for($z = $startZ; $z < $endZ; ++$z){ + for($x = $startX; $x < $endX; ++$x){ + $v = new Vector3($x, $y, $z); + if($this->isSupport($v)){ + $b = $this->server->api->block->getBlock($v); + if($b->isFlowable !== true){ + $support = true; + break; + } + } + } + if($support === true){ + break; + } + } if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB){ if($this->speedX != 0){ $this->x += $this->speedX * 5; @@ -318,7 +335,7 @@ class Entity extends stdClass{ if($this->speedZ != 0){ $this->z += $this->speedZ * 5; } - if($blockDown->isFlowable === true){ + if($support === false){ $this->speedY -= 0.04 * 5; //$this->server->api->handle("entity.motion", $this); }elseif($this->speedY < 0){ @@ -329,13 +346,18 @@ class Entity extends stdClass{ //$this->server->api->handle("entity.motion", $this); } }else{ - if($blockDown->isFlowable === true){ + if($support === false){ if($this->fallY === false){ $this->fallY = $y; $this->fallStart = microtime(true); + }elseif($this->class === ENTITY_PLAYER and ($this->fallStart + 5) < microtime(true)){ + if($this->player->gamemode === CREATIVE and $this->server->api->getProperty("allow-flight") !== true){ + $this->player->close("flying"); + return; + } }elseif($y > $this->fallY){ $this->fallY = $y; - } + } }elseif($this->fallY !== false){ //Fall damage! if($y < $this->fallY){ $d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z)); @@ -546,6 +568,16 @@ class Entity extends stdClass{ } return false; } + + public function isSupport(Vector3 $pos, $radius = 0.75){ + $me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5); + $diff = $pos->y - $this->y; + var_dump($diff); + if($me->distance($pos) < $radius and $diff >= -0.16 and $diff <= 0.6){ + return true; + } + return false; + } public function resetSpeed(){ $this->speedMeasure = array(0, 0, 0, 0, 0);