From b9eca491e8d02509c00279fa4bb8c82aeb1b8f3c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 4 Jan 2013 01:20:29 +0100 Subject: [PATCH] Updated triggers to handle or dhandle API method --- src/API/BlockAPI.php | 54 ++++++++----------- src/API/ConsoleAPI.php | 2 +- src/API/LevelAPI.php | 7 ++- src/API/ServerAPI.php | 4 ++ src/classes/Entity.class.php | 6 +-- src/classes/Player.class.php | 6 +-- src/classes/PocketMinecraftServer.class.php | 6 +-- .../generator/object/tree/PineTreeObject.php | 2 +- 8 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 7242184d6..a42cae0e9 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -45,12 +45,13 @@ class BlockAPI{ } private function cancelAction($block){ - $this->server->trigger("world.block.change", array( + $this->server->api->dhandle("world.block.change", array( "x" => $block[2][0], "y" => $block[2][1], "z" => $block[2][2], "block" => $block[0], "meta" => $block[1], + "fake" => true, )); return false; } @@ -135,16 +136,14 @@ class BlockAPI{ if($down[0] === 64){ $data2 = $data; --$data2["y"]; - $this->server->trigger("player.block.break", $data2); - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.break", $data2); } }else{ $up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]); if($up[0] === 64){ $data2 = $data; ++$data2["y"]; - $this->server->trigger("player.block.break", $data2); - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.break", $data2); } } break; @@ -152,8 +151,7 @@ class BlockAPI{ if($drop !== false and $drop[0] !== 0 and $drop[2] > 0){ $this->drop($data["x"], $data["y"], $data["z"], $drop[0], $drop[1] & 0x0F, $drop[2] & 0xFF); } - $this->server->trigger("player.block.break", $data); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.break", $data); return false; } @@ -203,8 +201,7 @@ class BlockAPI{ if($data["block"] === 292){ //Hoe $data["block"] = 60; $data["meta"] = 0; - $this->server->trigger("player.block.place", $data); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.place", $data); $cancelPlace = true; } case 59: @@ -212,8 +209,7 @@ class BlockAPI{ if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal $data["block"] = $target[0]; $data["meta"] = 0x07; - $this->server->trigger("player.block.place", $data); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.place", $data); $cancelPlace = true; } break; @@ -230,22 +226,23 @@ class BlockAPI{ "meta" => $down[1], "eid" => $data["eid"], ); - $this->server->trigger("player.block.update", $data2); - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + if($this->server->handle("player.block.update", $data2) !== false){ + $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + } } }else{ $data["block"] = $target[0]; $data["meta"] = $target[1] ^ 0x04; - $this->server->trigger("player.block.update", $data); - $up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]); - if($up[0] === 64){ - $data2 = $data; - $data2["meta"] = $up[1]; - ++$data2["y"]; - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + if($this->server->handle("player.block.update", $data) !== false){ + $up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]); + if($up[0] === 64){ + $data2 = $data; + $data2["meta"] = $up[1]; + ++$data2["y"]; + $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + } + $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); } - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); } $cancelPlace = true; break; @@ -253,8 +250,7 @@ class BlockAPI{ case 107: //Fence gates $data["block"] = $target[0]; $data["meta"] = $target[1] ^ 0x04; - $this->server->trigger("player.block.update", $data); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.update", $data); $cancelPlace = true; break; default: @@ -398,8 +394,7 @@ class BlockAPI{ $data2["meta"] = 0x08; $data["meta"] = $direction & 0x03; ++$data2["y"]; - $this->server->trigger("player.block.place", $data2); - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.place", $data2); } break; case 54: @@ -429,8 +424,7 @@ class BlockAPI{ $data2["x"] = $next[2][0]; $data2["y"] = $next[2][1]; $data2["z"] = $next[2][2]; - $this->server->trigger("player.block.place", $data2); - $this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.place", $data2); break; case 65: //Ladder if(isset(Material::$transparent[$target[0]])){ @@ -466,9 +460,7 @@ class BlockAPI{ } break; } - $this->server->trigger("player.block.place", $data); - $this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); - $this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL); + $this->server->handle("player.block.place", $data); return false; } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index f82a34812..e2601875c 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -249,7 +249,7 @@ class ConsoleAPI{ console("[INFO] Issued server command: /$cmd ".implode(" ", $params)); if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ call_user_func($this->cmds[$cmd], $cmd, $params); - }elseif($this->server->trigger("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ + }elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ $this->defaultCommands($cmd, $params); } } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index f6e52549a..a51d83a2d 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -88,13 +88,16 @@ class LevelAPI{ public function setBlock($x, $y, $z, $block, $meta = 0){ $this->map->setBlock($x, $y, $z, $block, $meta); $this->heightMap[$z][$x] = $this->map->getFloor($x, $z); - $this->server->trigger("world.block.change", array( + if($this->server->api->dhandle("world.block.change", array( "x" => $x, "y" => $y, "z" => $z, "block" => $block, "meta" => $meta, - )); + )) !== false){ + $this->server->api->block->updateBlock($x, $y, $z, BLOCK_UPDATE_NORMAL); + $this->server->api->block->updateBlocksAround($x, $y, $z, BLOCK_UPDATE_NORMAL); + } } public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){ diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index db50666d3..3e694d8be 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -294,6 +294,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run public function addHandler($e, $c, $p = 5){ return $this->server->addHandler($e, $c, $p); } + + public function dhandle($e, $d){ + return $this->server->handle($e, $d); + } public function handle($e, &$d){ return $this->server->handle($e, $d); diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 6145a9996..007b47102 100644 --- a/src/classes/Entity.class.php +++ b/src/classes/Entity.class.php @@ -151,7 +151,7 @@ class Entity extends stdClass{ public function close(){ if($this->closed === false){ $this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); - $this->server->trigger("entity.remove", $this->eid); + $this->server->api->dhandle("entity.remove", $this->eid); $this->server->deleteEvent($this->ev); $this->closed = true; } @@ -217,7 +217,7 @@ class Entity extends stdClass{ public function setHealth($health, $cause = ""){ $this->health = (int) $health; $this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";"); - $this->server->trigger("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause)); + $this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause)); if($this->player !== false){ $this->player->dataPacket(MC_SET_HEALTH, array( "health" => $this->health, @@ -226,7 +226,7 @@ class Entity extends stdClass{ if($this->health <= 0 and $this->dead === false){ $this->dead = true; if($this->player !== false){ - $this->server->handle("player.death", array("name" => $this->name, "cause" => $cause)); + $this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause)); } }elseif($this->health > 0){ $this->dead = false; diff --git a/src/classes/Player.class.php b/src/classes/Player.class.php index 109546e7c..d6d63672c 100644 --- a/src/classes/Player.class.php +++ b/src/classes/Player.class.php @@ -105,7 +105,7 @@ class Player{ $this->connected = false; if($msg === true){ - $this->server->trigger("server.chat", $this->username." left the game"); + $this->server->api->dhandle("server.chat", $this->username." left the game"); } console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason); $this->server->api->player->remove($this->CID); @@ -303,7 +303,7 @@ class Player{ case MC_MOVE_PLAYER: if(is_object($this->entity)){ $this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]); - $this->server->trigger("entity.move", $this->eid); + $this->server->api->dhandle("entity.move", $this->eid); } break; case MC_PLAYER_EQUIPMENT: @@ -354,7 +354,7 @@ class Player{ } break; case MC_ANIMATE: - $this->server->trigger("entity.animate", array("eid" => $this->eid, "action" => $data["action"])); + $this->server->api->dhandle("entity.animate", array("eid" => $this->eid, "action" => $data["action"])); break; case MC_RESPAWN: $this->entity->setHealth(20, "respawn"); diff --git a/src/classes/PocketMinecraftServer.class.php b/src/classes/PocketMinecraftServer.class.php index c45e5ab1c..bab6a24a6 100644 --- a/src/classes/PocketMinecraftServer.class.php +++ b/src/classes/PocketMinecraftServer.class.php @@ -88,8 +88,8 @@ class PocketMinecraftServer extends stdClass{ $this->event("server.chat", array($this, "eventHandler")); $this->event("player.new", array($this, "eventHandler")); - $this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->trigger("server.time.change", $this->time);'); - $this->action(5000000, 'if($this->difficulty < 2){$this->trigger("server.regeneration", 1);}'); + $this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time.change", $this->time);'); + $this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}'); $this->action(1000000 * 60, '$this->reloadConfig();'); $this->action(1000000 * 60 * 10, '$this->custom = array();'); if($this->api !== false){ @@ -167,7 +167,7 @@ class PocketMinecraftServer extends stdClass{ $message = "<".$owner."> "; } $message .= $text; - $this->trigger("server.chat", $message); + $this->handle("server.chat", $message); } public function setType($type = "normal"){ diff --git a/src/misc/world/generator/object/tree/PineTreeObject.php b/src/misc/world/generator/object/tree/PineTreeObject.php index 9718c462a..0d1cd0b8c 100644 --- a/src/misc/world/generator/object/tree/PineTreeObject.php +++ b/src/misc/world/generator/object/tree/PineTreeObject.php @@ -37,7 +37,7 @@ class PineTreeObject extends TreeObject{ public function canPlaceObject(LevelAPI $level, $x, $y, $z){ $this->findRandomLeavesSize(); $checkRadius = 0; - for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { + for($yy = 0; $yy < ($this->totalHeight + 2); ++$yy) { if($yy === $this->leavesSizeY) { $checkRadius = $this->leavesAbsoluteMaxRadius; }