mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
More fixes :D
This commit is contained in:
parent
7236f4aad6
commit
c27cca6741
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class Player{
|
||||
}
|
||||
|
||||
public function onTick($time, $event){
|
||||
if($event !== "server.tick"){ //WTF??
|
||||
if($event !== "server.tick" or $this->connected === false){
|
||||
return;
|
||||
}
|
||||
if($time > $this->timeout){
|
||||
@ -394,7 +394,16 @@ class Player{
|
||||
$this->dataPacket(MC_PLAYER_EQUIPMENT, $data);
|
||||
break;
|
||||
case "block.change":
|
||||
$this->dataPacket(MC_UPDATE_BLOCK, $data);
|
||||
if($data["position"]->level !== $this->level){
|
||||
break;
|
||||
}
|
||||
$this->dataPacket(MC_UPDATE_BLOCK, array(
|
||||
"x" => $data["position"]->x,
|
||||
"y" => $data["position"]->y,
|
||||
"z" => $data["position"]->z,
|
||||
"block" => $data["block"]->getID(),
|
||||
"meta" => $data["block"]->getMetadata(),
|
||||
));
|
||||
break;
|
||||
case "entity.move":
|
||||
if($data->eid === $this->eid){
|
||||
@ -875,7 +884,7 @@ class Player{
|
||||
}
|
||||
$this->spawned = true;
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
$this->server->api->entity->spawnToAll($this->eid);
|
||||
$this->server->api->entity->spawnToAll($this->level, $this->eid);
|
||||
$this->server->schedule(5, array($this->entity, "update"), array(), true);
|
||||
$this->sendArmor();
|
||||
$this->eventHandler(new Container($this->server->motd), "server.chat");
|
||||
@ -1123,7 +1132,7 @@ class Player{
|
||||
$t->data["Text3"] = $data["line2"];
|
||||
$t->data["Text4"] = $data["line3"];
|
||||
$this->server->handle("tile.update", $t);
|
||||
$this->server->api->tileentity->spawnToAll($t);
|
||||
$this->server->api->tileentity->spawnToAll($this->level, $t);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -39,7 +39,7 @@ class GenericBlock extends Block{
|
||||
}
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
return $this->level->setBlock($this, BlockAPI::getBlock(AIR, 0));
|
||||
return $this->level->setBlock($this, new AirBlock());
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
|
@ -334,7 +334,7 @@ class PMFLevel extends PMF{
|
||||
$bindex = $aY + ($aX << 5) + ($aZ << 9);
|
||||
$mindex = ($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9);
|
||||
$old_b = $this->chunks[$index][$Y]{$bindex};
|
||||
$old_m = ord($this->map[$X][$Z][1][$index]{$y >> 1});
|
||||
$old_m = $this->chunks[$index][$Y]{$mindex};
|
||||
if(($y & 1) === 0){
|
||||
$old_m = $old_m & 0x0F;
|
||||
$m = ($old_m << 4) | ($meta & 0x0F);
|
||||
|
@ -470,6 +470,9 @@ class Entity extends Position{
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"yaw" => $this->yaw,
|
||||
"pitch" => $this->pitch,
|
||||
"roll" => 0,
|
||||
"block" => $this->type,
|
||||
"meta" => $this->meta,
|
||||
"stack" => $this->stack,
|
||||
|
Loading…
x
Reference in New Issue
Block a user