diff --git a/src/Player.php b/src/Player.php index 679f9698..0035550f 100755 --- a/src/Player.php +++ b/src/Player.php @@ -890,7 +890,16 @@ class Player{ } } } - + public function makeInvisibleForOnePlayer(Player $player){ + $pk = new RemoveEntityPacket; + $pk->eid = $this->entity->eid; + $player->dataPacket($pk); + } + public function makeInvisibleForAllPlayers(){ + $pk = new RemoveEntityPacket; + $pk->eid = $this->entity->eid; + $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); + } public function getGamemode(){ switch($this->gamemode){ case SURVIVAL: @@ -941,6 +950,14 @@ class Player{ $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); $this->server->schedule(30, [$this, "close"], "gamemode change"); //Forces a kick } + + if($this->gamemode === SPECTATOR){ + $this->makeInvisibleForAllPlayers(); + } + if($this->gamemode === CREATIVE){ + $this->server->api->player->spawnToAllPlayers($this); + } + $this->inventory = $inv; $this->sendSettings(); $this->sendInventory(); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0fdd1a68..3838db29 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -587,7 +587,9 @@ class Entity extends Position{ if($this->player->connected !== true or $this->player->spawned === false){ return false; } - + if($this->player->gamemode === SPECTATOR){ + break; + } $pk = new AddPlayerPacket; $pk->clientID = 0; //$this->player->clientID; $pk->username = $this->player->username;