mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
Added correct handling of RemovePlayer packet for in-game player list
This commit is contained in:
parent
d26d657b95
commit
7102787aa9
@ -148,9 +148,11 @@ class EntityAPI{
|
|||||||
|
|
||||||
public function spawnAll(Player $player){
|
public function spawnAll(Player $player){
|
||||||
foreach($this->getAll($player->level) as $e){
|
foreach($this->getAll($player->level) as $e){
|
||||||
|
if($e->class !== ENTITY_PLAYER){
|
||||||
$e->spawn($player);
|
$e->spawn($player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function remove($eid){
|
public function remove($eid){
|
||||||
if(isset($this->entities[$eid])){
|
if(isset($this->entities[$eid])){
|
||||||
@ -159,6 +161,16 @@ class EntityAPI{
|
|||||||
unset($this->entities[$eid]);
|
unset($this->entities[$eid]);
|
||||||
$entity->closed = true;
|
$entity->closed = true;
|
||||||
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";");
|
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";");
|
||||||
|
if($entity->class === ENTITY_PLAYER){
|
||||||
|
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), MC_REMOVE_PLAYER, array(
|
||||||
|
"clientID" => 0,
|
||||||
|
"eid" => $entity->eid,
|
||||||
|
));
|
||||||
|
}else{
|
||||||
|
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), MC_REMOVE_ENTITY, array(
|
||||||
|
"eid" => $entity->eid,
|
||||||
|
));
|
||||||
|
}
|
||||||
$this->server->api->dhandle("entity.remove", $entity);
|
$this->server->api->dhandle("entity.remove", $entity);
|
||||||
$entity = null;
|
$entity = null;
|
||||||
unset($entity);
|
unset($entity);
|
||||||
|
@ -376,6 +376,42 @@ class PlayerAPI{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function spawnAllPlayers(Player $player){
|
||||||
|
foreach($this->getAll() as $p){
|
||||||
|
if($p !== $player){
|
||||||
|
$p->entity->spawn($player);
|
||||||
|
if($p->level !== $player->level){
|
||||||
|
$player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
|
"eid" => $p->entity->eid,
|
||||||
|
"x" => -256,
|
||||||
|
"y" => 128,
|
||||||
|
"z" => -256,
|
||||||
|
"yaw" => 0,
|
||||||
|
"pitch" => 0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function spawnToAllPlayers(Player $player){
|
||||||
|
foreach($this->getAll() as $p){
|
||||||
|
if($p !== $player){
|
||||||
|
$player->entity->spawn($p);
|
||||||
|
if($p->level !== $player->level){
|
||||||
|
$p->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
|
"eid" => $player->entity->eid,
|
||||||
|
"x" => -256,
|
||||||
|
"y" => 128,
|
||||||
|
"z" => -256,
|
||||||
|
"yaw" => 0,
|
||||||
|
"pitch" => 0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function remove($CID){
|
public function remove($CID){
|
||||||
if(isset($this->server->clients[$CID])){
|
if(isset($this->server->clients[$CID])){
|
||||||
$player = $this->server->clients[$CID];
|
$player = $this->server->clients[$CID];
|
||||||
|
@ -269,9 +269,6 @@ class Player{
|
|||||||
$this->level->freeAllChunks($this);
|
$this->level->freeAllChunks($this);
|
||||||
$this->spawned = false;
|
$this->spawned = false;
|
||||||
$this->loggedIn = false;
|
$this->loggedIn = false;
|
||||||
if($msg === true and $this->username != ""){
|
|
||||||
$this->server->api->chat->broadcast($this->username." left the game");
|
|
||||||
}
|
|
||||||
$this->buffer = null;
|
$this->buffer = null;
|
||||||
unset($this->buffer);
|
unset($this->buffer);
|
||||||
$this->recoveryQueue = array();
|
$this->recoveryQueue = array();
|
||||||
@ -509,14 +506,6 @@ class Player{
|
|||||||
"speedZ" => (int) ($data->speedZ * 400),
|
"speedZ" => (int) ($data->speedZ * 400),
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "entity.remove":
|
|
||||||
if($data->eid === $this->eid or $data->level !== $this->level){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$this->dataPacket(MC_REMOVE_ENTITY, array(
|
|
||||||
"eid" => $data->eid,
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
case "entity.animate":
|
case "entity.animate":
|
||||||
if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){
|
if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){
|
||||||
break;
|
break;
|
||||||
@ -725,15 +714,31 @@ class Player{
|
|||||||
foreach($this->server->api->entity->getAll($this->level) as $e){
|
foreach($this->server->api->entity->getAll($this->level) as $e){
|
||||||
if($e !== $this->entity){
|
if($e !== $this->entity){
|
||||||
if($e->player instanceof Player){
|
if($e->player instanceof Player){
|
||||||
$e->player->dataPacket(MC_REMOVE_ENTITY, array(
|
$e->player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
"eid" => $this->eid,
|
"eid" => $this->entity->eid,
|
||||||
|
"x" => -256,
|
||||||
|
"y" => 128,
|
||||||
|
"z" => -256,
|
||||||
|
"yaw" => 0,
|
||||||
|
"pitch" => 0,
|
||||||
));
|
));
|
||||||
}
|
$player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
|
"eid" => $e->eid,
|
||||||
|
"x" => -256,
|
||||||
|
"y" => 128,
|
||||||
|
"z" => -256,
|
||||||
|
"yaw" => 0,
|
||||||
|
"pitch" => 0,
|
||||||
|
));
|
||||||
|
}else{
|
||||||
$this->dataPacket(MC_REMOVE_ENTITY, array(
|
$this->dataPacket(MC_REMOVE_ENTITY, array(
|
||||||
"eid" => $e->eid,
|
"eid" => $e->eid,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->level->freeAllChunks($this);
|
$this->level->freeAllChunks($this);
|
||||||
$this->level = $pos->level;
|
$this->level = $pos->level;
|
||||||
$this->chunksLoaded = array();
|
$this->chunksLoaded = array();
|
||||||
@ -743,6 +748,38 @@ class Player{
|
|||||||
"time" => $this->level->getTime(),
|
"time" => $this->level->getTime(),
|
||||||
));
|
));
|
||||||
$terrain = true;
|
$terrain = true;
|
||||||
|
foreach($this->server->api->player->getAll($this->level) as $player){
|
||||||
|
$player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
|
"eid" => $this->entity->eid,
|
||||||
|
"x" => $pos->x,
|
||||||
|
"y" => $pos->y,
|
||||||
|
"z" => $pos->z,
|
||||||
|
"yaw" => $yaw,
|
||||||
|
"pitch" => $pitch,
|
||||||
|
));
|
||||||
|
$this->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||||
|
"eid" => $player->entity->eid,
|
||||||
|
"x" => $player->entity->x,
|
||||||
|
"y" => $player->entity->y,
|
||||||
|
"z" => $player->entity->z,
|
||||||
|
"yaw" => $player->entity->yaw,
|
||||||
|
"pitch" => $player->entity->pitch,
|
||||||
|
));
|
||||||
|
$player->dataPacket(MC_PLAYER_EQUIPMENT, array(
|
||||||
|
"eid" => $this->eid,
|
||||||
|
"block" => $this->getSlot($this->slot)->getID(),
|
||||||
|
"meta" => $this->getSlot($this->slot)->getMetadata(),
|
||||||
|
"slot" => 0,
|
||||||
|
));
|
||||||
|
$this->sendArmor($player);
|
||||||
|
$this->dataPacket(MC_PLAYER_EQUIPMENT, array(
|
||||||
|
"eid" => $player->eid,
|
||||||
|
"block" => $player->getSlot($player->slot)->getID(),
|
||||||
|
"meta" => $player->getSlot($player->slot)->getMetadata(),
|
||||||
|
"slot" => 0,
|
||||||
|
));
|
||||||
|
$player->sendArmor($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->lastCorrect = $pos;
|
$this->lastCorrect = $pos;
|
||||||
$this->entity->fallY = false;
|
$this->entity->fallY = false;
|
||||||
@ -1153,7 +1190,6 @@ class Player{
|
|||||||
$this->entity->setName($this->username);
|
$this->entity->setName($this->username);
|
||||||
$this->entity->data["CID"] = $this->CID;
|
$this->entity->data["CID"] = $this->CID;
|
||||||
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
|
|
||||||
$this->evid[] = $this->server->event("entity.motion", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("entity.motion", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler"));
|
||||||
@ -1176,9 +1212,12 @@ class Player{
|
|||||||
if($this->spawned !== false){
|
if($this->spawned !== false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$this->server->api->player->spawnAllPlayers($this);
|
||||||
|
$this->server->api->player->spawnToAllPlayers($this);
|
||||||
$this->spawned = true;
|
$this->spawned = true;
|
||||||
$this->server->api->entity->spawnAll($this);
|
$this->server->api->entity->spawnAll($this);
|
||||||
$this->server->api->entity->spawnToAll($this->entity);
|
$this->server->api->entity->spawnToAll($this->entity);
|
||||||
|
|
||||||
$this->server->schedule(5, array($this->entity, "update"), array(), true);
|
$this->server->schedule(5, array($this->entity, "update"), array(), true);
|
||||||
$this->sendArmor();
|
$this->sendArmor();
|
||||||
$this->sendChat($this->server->motd."\n");
|
$this->sendChat($this->server->motd."\n");
|
||||||
|
@ -589,12 +589,12 @@ class Entity extends Position{
|
|||||||
if(!($player instanceof Player)){
|
if(!($player instanceof Player)){
|
||||||
$player = $this->server->api->player->get($player);
|
$player = $this->server->api->player->get($player);
|
||||||
}
|
}
|
||||||
if($player->eid === $this->eid or $this->closed !== false or $player->level !== $this->level){
|
if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch($this->class){
|
switch($this->class){
|
||||||
case ENTITY_PLAYER:
|
case ENTITY_PLAYER:
|
||||||
if($this->player->connected !== true){
|
if($this->player->connected !== true or $this->spawned === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$player->dataPacket(MC_ADD_PLAYER, array(
|
$player->dataPacket(MC_ADD_PLAYER, array(
|
||||||
@ -922,16 +922,14 @@ class Entity extends Position{
|
|||||||
$this->updateMetadata();
|
$this->updateMetadata();
|
||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
if($this->player instanceof Player){
|
if($this->player instanceof Player){
|
||||||
$x = $this->x;
|
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_MOVE_ENTITY_POSROT, array(
|
||||||
$y = $this->y;
|
"eid" => $this->eid,
|
||||||
$z = $this->z;
|
"x" => -256,
|
||||||
$this->x = 0;
|
"y" => 128,
|
||||||
$this->y = -10;
|
"z" => -256,
|
||||||
$this->z = 0;
|
"yaw" => 0,
|
||||||
$this->server->api->trigger("entity.move", $this);
|
"pitch" => 0,
|
||||||
$this->x = $x;
|
));
|
||||||
$this->y = $y;
|
|
||||||
$this->z = $z;
|
|
||||||
}else{
|
}else{
|
||||||
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
|
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user