diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index c53804af..f4d6375e 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -112,21 +112,9 @@ class EntityAPI{ return $this->entities[$eid]; } - public function spawnTo($eid, $player){ - $e = $this->get($eid); - if($e === false){ - return false; - } - $e->spawn($player); - } - - public function spawnToAll(Level $level, $eid){ - $e = $this->get($eid); - if($e === false){ - return false; - } - foreach($this->server->api->player->getAll($level) as $player){ - if($player->eid !== false and $player->eid !== $eid){ + public function spawnToAll(Entity $e){ + foreach($this->server->api->player->getAll($e->level) as $player){ + if($player->eid !== false and $player->eid !== $e->eid){ $e->spawn($player); } } @@ -150,7 +138,7 @@ class EntityAPI{ $item->count = min($item->getMaxStackSize(), $count); $count -= $item->count; $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); - $this->spawnToAll($pos->level, $e->eid); + $this->spawnToAll($e); $this->server->api->handle("entity.motion", $e); } } diff --git a/src/API/TileEntityAPI.php b/src/API/TileEntityAPI.php index 4709959f..6d02f221 100644 --- a/src/API/TileEntityAPI.php +++ b/src/API/TileEntityAPI.php @@ -75,7 +75,7 @@ class TileEntityAPI{ public function add(Level $level, $class, $x, $y, $z, $data = array()){ $id = $this->tCnt++; $this->tileEntities[$id] = new TileEntity($level, $id, $class, $x, $y, $z, $data); - $this->spawnToAll($level, $id); + $this->spawnToAll($this->tileEntities[$id]); return $this->tileEntities[$id]; } @@ -92,20 +92,8 @@ class TileEntityAPI{ )); } - public function spawnTo($id, $player){ - $t = $this->getByID($id); - if($t === false){ - return false; - } - $t->spawn($player); - } - - public function spawnToAll(Level $level, $id){ - $t = $this->getByID($id); - if($t === false){ - return false; - } - foreach($this->server->api->player->getAll($level) as $player){ + public function spawnToAll(TileEntity $t){ + foreach($this->server->api->player->getAll($t->level) as $player){ if($player->eid !== false){ $t->spawn($player); } @@ -126,6 +114,7 @@ class TileEntityAPI{ $t->closed = true; $t->close(); $this->server->query("DELETE FROM tileentities WHERE ID = ".$id.";"); + $this->server->api->dhandle("tile.remove", $t); $t = null; unset($t); } diff --git a/src/Player.php b/src/Player.php index c92f63cf..2b8662e0 100644 --- a/src/Player.php +++ b/src/Player.php @@ -171,7 +171,10 @@ class Player{ $tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND level = '".$this->level->getName()."' 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); + $tile = $this->server->api->tileentitiy->getByID($tile["ID"]); + if($tile instanceof TileEntity){ + $tile->spawn($this); + } } } @@ -636,7 +639,7 @@ class Player{ $this->level->freeAllChunks($this); $this->level = $pos->level; $this->chunksLoaded = array(); - $this->server->api->entity->spawnToAll($this->level, $this->eid); + $this->server->api->entity->spawnToAll($this->entity); $this->server->api->entity->spawnAll($this); $terrain = true; } @@ -987,7 +990,7 @@ class Player{ } $this->spawned = true; $this->server->api->entity->spawnAll($this); - $this->server->api->entity->spawnToAll($this->level, $this->eid); + $this->server->api->entity->spawnToAll($this->entity); $this->server->schedule(5, array($this->entity, "update"), array(), true); $this->sendArmor(); $this->eventHandler(new Container($this->server->motd), "server.chat"); @@ -1089,7 +1092,7 @@ class Player{ "z" => $this->entity->z, ); $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d); - $this->server->api->entity->spawnToAll($this->level, $e->eid); + $this->server->api->entity->spawnToAll($e); } } break; @@ -1396,7 +1399,7 @@ class Player{ "meta" => $data[1], "stack" => $data[2], )); - $this->server->api->entity->spawnTo($e->eid, $this); + $e->spawn($this); } $this->inventory[$s] = array(AIR, 0, 0); }*/ diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index fa909996..816540c1 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -55,7 +55,7 @@ class GenericBlock extends Block{ $server = ServerAPI::request(); $this->level->setBlock($this, new AirBlock(), false, false, true); $e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data); - $server->api->entity->spawnToAll($this->level, $e->eid); + $server->api->entity->spawnToAll($e); $server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1); } return false; diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index 9bf02367..15abc923 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -79,7 +79,7 @@ class PaintingItem extends Item{ "Motive" => $motive[0], ); $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); - $server->api->entity->spawnToAll($level, $e->eid); + $server->api->entity->spawnToAll($e); if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($this->getID(), $this->getMetadata(), 1); }