More fixes :D

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-14 21:54:01 +02:00
parent 7236f4aad6
commit c27cca6741
9 changed files with 56 additions and 44 deletions

View file

@ -83,7 +83,7 @@ class BanAPI{
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
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"]);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){
return false;
}

View file

@ -282,36 +282,12 @@ class BlockAPI{
if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
foreach($drops as $drop){
$this->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF));
$this->server->api->entity->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF));
}
}
return false;
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = array(
"x" => $pos->x + mt_rand(2, 8) / 10,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(2, 8) / 10,
"item" => $item,
);
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$server = ServerAPI::request();
$e = $server->api->entity->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
//$e->speedX = mt_rand(-10, 10) / 100;
//$e->speedY = mt_rand(0, 5) / 100;
//$e->speedZ = mt_rand(-10, 10) / 100;
$server->api->entity->spawnToAll($e->eid);
}
}
}
public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz){
if($face < 0 or $face > 5){
return false;
@ -351,6 +327,7 @@ class BlockAPI{
if($item->isPlaceable()){
$hand = $item->getBlock();
$hand->position($block);
}else{
return $this->cancelAction($block, $player);
}
@ -368,7 +345,7 @@ class BlockAPI{
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){
return $this->cancelAction($block, $player);
}
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_POST){
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
$t = $this->server->api->tileentity->addSign($player->level, $block->x, $block->y, $block->z);
$t->data["creator"] = $player->username;
}

View file

@ -49,7 +49,7 @@ class EntityAPI{
public function getAll($level = null){
if($level instanceof Level){
$entities = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."';");
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
@ -90,20 +90,43 @@ class EntityAPI{
$e->spawn($player);
}
public function spawnToAll($eid){
public function spawnToAll(Level $level, $eid){
$e = $this->get($eid);
if($e === false){
return false;
}
foreach($this->server->api->player->getAll() as $player){
foreach($this->server->api->player->getAll($level) as $player){
if($player->eid !== false and $player->eid !== $eid){
$e->spawn($player);
}
}
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = array(
"x" => $pos->x + mt_rand(2, 8) / 10,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(2, 8) / 10,
"item" => $item,
);
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
//$e->speedX = mt_rand(-10, 10) / 100;
//$e->speedY = mt_rand(0, 5) / 100;
//$e->speedZ = mt_rand(-10, 10) / 100;
$this->spawnToAll($pos->level, $e->eid);
}
}
}
public function spawnAll($player){
foreach($this->getAll() as $e){
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $e){
$e->spawn($player);
}
}

View file

@ -253,12 +253,12 @@ class PlayerAPI{
public function getAll($level = null){
if($level instanceof Level){
$clients = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."' AND class = '".ENTITY_PLAYER."';");
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."' AND class = '".ENTITY_PLAYER."';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->getByEID($e["EID"]);
if($e instanceof Player){
$clients[$e->clientID] = $e->player;
$clients[$e->clientID] = $e;
}
}
}

View file

@ -68,7 +68,7 @@ class TileEntityAPI{
public function getAll($level = null){
if($level instanceof Level){
$tileEntities = array();
$l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$this->level->getName()."';");
$l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$level->getName()."';");
if($l !== false and $l !== true){
while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$t = $this->get($e["ID"]);
@ -115,15 +115,15 @@ class TileEntityAPI{
if($t === false){
return false;
}
foreach($this->server->api->player->getAll() as $player){
foreach($this->server->api->player->getAll($level) as $player){
if($player->eid !== false){
$t->spawn($player);
}
}
}
public function spawnAll($player){
foreach($this->getAll() as $t){
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $t){
$t->spawn($player);
}
}