From 450b5d9560d72e9757438d8f65450c76ab30a946 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 May 2013 23:13:01 +0200 Subject: [PATCH] Updated TileEntity API [fixes #306] --- src/API/TileEntityAPI.php | 18 ++++-------------- src/Player.php | 3 +-- src/material/block/solid/BurningFurnace.php | 20 ++------------------ src/material/block/solid/Chest.php | 20 ++------------------ src/world/Level.php | 2 +- 5 files changed, 10 insertions(+), 53 deletions(-) diff --git a/src/API/TileEntityAPI.php b/src/API/TileEntityAPI.php index 9ce2f89f..78bbcb6f 100644 --- a/src/API/TileEntityAPI.php +++ b/src/API/TileEntityAPI.php @@ -35,21 +35,11 @@ class TileEntityAPI{ } public function get(Position $pos){ - $tiles = $this->server->query("SELECT * FROM tileentities WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};"); - $ret = array(); - if($tiles !== false and $tiles !== true){ - while(($t = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){ - if(($tile = $this->getByID($t["ID"])) !== false){ - if($tile->normal === true){ - $ret[] = $tile; - } - } - } + $tile = $this->server->query("SELECT * FROM tileentities WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true); + if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){ + return $tile; } - if(count($ret) === 0){ - return false; - } - return $ret; + return false; } public function getByID($id){ diff --git a/src/Player.php b/src/Player.php index 95a5df96..108634c0 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1240,8 +1240,7 @@ class Player{ break; } $t = $this->server->api->tileentity->get(new Position($data["x"], $data["y"], $data["z"], $this->level)); - if(($t[0] instanceof TileEntity) and $t[0]->class === TILE_SIGN){ - $t = $t[0]; + if(($t instanceof TileEntity) and $t->class === TILE_SIGN){ if($t->data["creator"] !== $this->username){ $t->spawn($this); }else{ diff --git a/src/material/block/solid/BurningFurnace.php b/src/material/block/solid/BurningFurnace.php index 68f406ce..760997e7 100644 --- a/src/material/block/solid/BurningFurnace.php +++ b/src/material/block/solid/BurningFurnace.php @@ -46,19 +46,7 @@ class BurningFurnaceBlock extends SolidBlock{ public function onBreak(Item $item, Player $player){ $server = ServerAPI::request(); - $t = $server->api->tileentity->get($this); - if($t !== false){ - if(is_array($t)){ - foreach($t as $ts){ - if($ts->class === TILE_FURNACE){ - $server->api->tileentity->remove($ts->id); - } - } - }elseif($t->class === TILE_FURNACE){ - $server->api->tileentity->remove($t->id); - } - } - $this->level->setBlock($this, new AirBlock()); + $this->level->setBlock($this, new AirBlock(), true, true); return true; } @@ -68,11 +56,7 @@ class BurningFurnaceBlock extends SolidBlock{ $t = $server->api->tileentity->get($this); $furnace = false; if($t !== false){ - if(is_array($t)){ - $furnace = array_shift($t); - }else{ - $furnace = $t; - } + $furnace = $t; }else{ $furnace = $server->api->tileentity->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array( "Items" => array(), diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index 049a350e..ef06fc1d 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -59,19 +59,7 @@ class ChestBlock extends TransparentBlock{ public function onBreak(Item $item, Player $player){ $server = ServerAPI::request(); - $t = $server->api->tileentity->get($this); - if($t !== false){ - if(is_array($t)){ - foreach($t as $ts){ - if($ts->class === TILE_CHEST){ - $server->api->tileentity->remove($ts->id); - } - } - }elseif($t->class === TILE_CHEST){ - $server->api->tileentity->remove($t->id); - } - } - $this->level->setBlock($this, new AirBlock()); + $this->level->setBlock($this, new AirBlock(), true, true); return true; } @@ -85,11 +73,7 @@ class ChestBlock extends TransparentBlock{ $t = $server->api->tileentity->get($this); $chest = false; if($t !== false){ - if(is_array($t)){ - $chest = array_shift($t); - }else{ - $chest = $t; - } + $chest = $t; }else{ $chest = $server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array( "Items" => array(), diff --git a/src/world/Level.php b/src/world/Level.php index e0b656d6..95c8fbe7 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -247,7 +247,7 @@ class Level{ } if($tiles === true){ if(($t = $this->server->api->tileentity->get($pos)) !== false){ - $t[0]->close(); + $t->close(); } } }