diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index e29486cc0..bd98fed3e 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -256,7 +256,7 @@ class BlockAPI{ } if($player instanceof Player){ - if($player->gamemode === CREATIVE){ + if(($player->gamemode & 0x01) === 0x01){ $output .= "Player is in creative mode.\n"; break; } @@ -283,6 +283,9 @@ class BlockAPI{ "block" => $block->getID(), "meta" => $block->getMetadata() )); + if($player->itemEnforcement === true){ + $player->sendInventory(); + } return false; } @@ -295,7 +298,7 @@ class BlockAPI{ return $this->cancelAction($target, $player); } - if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or $player->gamemode === ADVENTURE or ($player->lastBreak + $target->getBreakTime($item, $player)) >= microtime(true)){ + if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or ($player->lastBreak + $target->getBreakTime($item, $player)) >= microtime(true)){ return $this->cancelAction($target, $player); } @@ -309,7 +312,7 @@ class BlockAPI{ } - if($player->gamemode !== CREATIVE and count($drops) > 0){ + 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)); } @@ -366,7 +369,7 @@ class BlockAPI{ } } - if($player->gamemode === ADVENTURE){ //Adventure mode!! + if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!! return $this->cancelAction($block, $player); } @@ -402,7 +405,7 @@ class BlockAPI{ $t->data["creator"] = $player->username; } - if($player->gamemode !== CREATIVE){ + if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($item->getID(), $item->getMetadata(), 1); } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index d0bbe1dd1..03aec977d 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -132,7 +132,12 @@ class PlayerAPI{ "c" => CREATIVE, "2" => ADVENTURE, "adventure" => ADVENTURE, - "a" => ADVENTURE, + "a" => ADVENTURE, + "3" => VIEW, + "view" => VIEW, + "viewer" => VIEW, + "spectator" => VIEW, + "v" => VIEW, ); if($issuer instanceof Player){ $player = $issuer; @@ -328,7 +333,7 @@ class PlayerAPI{ console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); $data->save(); } - if($this->server->gamemode === CREATIVE){ + if(($this->server->gamemode & 0x01) === 0x01){ $data->set("health", 20); } $this->server->handle("player.offline.get", $data); diff --git a/src/Player.php b/src/Player.php index 6586f64e4..41a367617 100644 --- a/src/Player.php +++ b/src/Player.php @@ -275,7 +275,7 @@ class Player{ public function sendInventorySlot($s){ $s = (int) $s; - if(!isset($this->inventory[$s]) or ($this->itemEnforcement === false and $this->gamemode !== CREATIVE)){ + if(!isset($this->inventory[$s]) or $this->itemEnforcement === false){ return false; } @@ -346,7 +346,7 @@ class Player{ if($data["eid"] === $this->eid){ $data["eid"] = 0; $this->dataPacket(MC_TAKE_ITEM_ENTITY, $data); - if(($this->gamemode === SURVIVAL or $this->gamemode === ADVENTURE)){ + if(($this->gamemode & 0x01) === 0x00){ $this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack); } }else{ @@ -491,8 +491,8 @@ class Player{ 0x80000000 ? */ $flags = 0; - if($this->gamemode === ADVENTURE){ - $flags |= 0x01; //Not allow placing/breaking blocks + if(($this->gamemode & 0x02) === 0x02){ + $flags |= 0x01; //Not allow placing/breaking blocks, adventure mode } if($nametags !== false){ @@ -542,17 +542,26 @@ class Player{ return "creative"; case ADVENTURE: return "adventure"; + case VIEW: + return "view"; } } public function setGamemode($gm){ - if($gm < 0 or $gm > 2 or $this->gamemode === $gm){ + if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ return false; } - if(($this->gamemode === SURVIVAL and $gm === ADVENTURE) or ($this->gamemode === ADVENTURE and $gm === SURVIVAL)){ + if(($this->gamemode & 0x01) === ($gm & 0x01)){ $this->gamemode = $gm; $this->sendSettings(); + if(($this->gamemode & 0x01) === 0x01 and ($this->gamemode & 0x02) === 0x02){ + $this->inventory = array(); + foreach(BlockAPI::$creative as $item){ + $this->inventory[] = array(AIR, 0, 0); + } + $this->sendInventory(); + } $this->eventHandler("Your gamemode has been changed to ".$this->getGamemode().".", "server.chat"); }else{ $this->blocked = true; @@ -741,12 +750,18 @@ class Player{ } $this->auth = true; - if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){ - if($this->gamemode === CREATIVE){ + if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){ + if(($this->gamemode & 0x01) === 0x01){ $this->itemEnforcement = true; $this->inventory = array(); - foreach(BlockAPI::$creative as $item){ - $this->inventory[] = array($item[0], $item[1], 1); + if(($this->gamemode & 0x02) === 0x02){ + foreach(BlockAPI::$creative as $item){ + $this->inventory[] = array(AIR, 0, 0); + } + }else{ + foreach(BlockAPI::$creative as $item){ + $this->inventory[] = array($item[0], $item[1], 1); + } } } $this->data->set("inventory", $this->inventory); @@ -773,8 +788,8 @@ class Player{ "gamemode" => $this->gamemode, "eid" => 0, )); - if($this->gamemode === CREATIVE){ - $this->equipment = BlockAPI::getItem(STONE); + if(($this->gamemode & 0x01) === 0x01){ + $this->equipment = BlockAPI::getItem($this->inventory[7][0], $this->inventory[7][1], $this->inventory[7][2]); } $this->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this)); $this->eid = $this->entity->eid; @@ -844,7 +859,7 @@ class Player{ if(($this->entity instanceof Entity) and $data["counter"] > $this->lastMovement){ $this->lastMovement = $data["counter"]; $speed = $this->entity->getSpeed(); - if($this->blocked === true or ($speed > 5 and $this->gamemode !== CREATIVE) or $speed > 13 or $this->server->api->handle("player.move", $this->entity) === false){ + if($this->blocked === true or ($speed > 5 and ($this->gamemode & 0x01) === 0x00) or $speed > 13 or $this->server->api->handle("player.move", $this->entity) === false){ if($this->lastCorrect instanceof Vector3){ $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); } @@ -908,7 +923,7 @@ class Player{ $data["entity"] = $this->entity; if(!($target instanceof Entity)){ break; - }elseif($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or $target->player->gamemode === CREATIVE)){ + }elseif($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){ break; }elseif($this->handle("player.interact", $data) !== false){ switch($this->equipment->getID()){ @@ -1000,7 +1015,7 @@ class Player{ if($this->spawned === false){ break; } - if($this->gamemode === CREATIVE){ + if(($this->gamemode & 0x01) === 0x01){ break; } //$this->entity->setHealth($data["health"], "client"); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 9b628defa..8f36fe365 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -291,6 +291,8 @@ class PocketMinecraftServer{ return "creative"; case ADVENTURE: return "adventure"; + case VIEW: + return "view"; } } @@ -515,7 +517,7 @@ class PocketMinecraftServer{ $data[0], $this->serverID, RAKNET_MAGIC, - $this->serverType. $this->name . " [".($this->gamemode === CREATIVE ? "C":($this->gamemode === ADVENTURE ? "A":"S")).($this->whitelist !== false ? "W":"")." ".count($this->clients)."/".$this->maxClients."] ".$txt, + $this->serverType. $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt, ), false, $packet["ip"], $packet["port"]); $this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); break; diff --git a/src/constants/GeneralConstants.php b/src/constants/GeneralConstants.php index 29f50a7c8..d58f9efd3 100644 --- a/src/constants/GeneralConstants.php +++ b/src/constants/GeneralConstants.php @@ -28,4 +28,5 @@ the Free Software Foundation, either version 3 of the License, or //Gamemodes define("SURVIVAL", 0); define("CREATIVE", 1); -define("ADVENTURE", 2); \ No newline at end of file +define("ADVENTURE", 2); +define("VIEW", 3); \ No newline at end of file diff --git a/src/material/Block.php b/src/material/Block.php index a50f8a64d..1d7aece94 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -191,7 +191,7 @@ abstract class Block extends Vector3{ } public function getBreakTime(Item $item, Player $player){ - if($player->gamemode === CREATIVE){ + if(($player->gamemode & 0x01) === 0x01){ return 0.25; } return $this->breakTime; diff --git a/src/material/block/solid/Bedrock.php b/src/material/block/solid/Bedrock.php index 741871840..259d94515 100644 --- a/src/material/block/solid/Bedrock.php +++ b/src/material/block/solid/Bedrock.php @@ -32,7 +32,7 @@ class BedrockBlock extends SolidBlock{ } public function isBreakable(Item $item, Player $player){ - if($player->gamemode === CREATIVE){ + if(($player->gamemode & 0x01) === 0x01){ return true; } return false; diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index d0ff70e8e..7b12d5a1b 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -60,7 +60,7 @@ class PaintingItem extends Item{ $server = ServerAPI::request(); $e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data); $server->api->entity->spawnToAll($e->eid); - if($player->gamemode !== CREATIVE){ + if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($this->getID(), $this->getMetadata(), 1); } return true; diff --git a/src/world/Entity.php b/src/world/Entity.php index 9ea4509d9..97fd258cd 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -194,7 +194,7 @@ class Entity extends stdClass{ }else{ return false; } - if(($player instanceof Player) and ($player->gamemode === SURVIVAL or $player->gamemode === ADVENTURE) and $player->spawned === true){ + if(($player instanceof Player) and ($player->gamemode & 0x01) === 0x00 and $player->spawned === true){ if($this->server->api->dhandle("player.pickup", array( "eid" => $player->eid, "player" => $player, @@ -346,7 +346,7 @@ class Entity extends stdClass{ //$this->server->api->handle("entity.motion", $this); } }elseif($this->class === ENTITY_PLAYER){ - if($support === false and $this->player->gamemode !== CREATIVE){ + if($support === false and ($this->player->gamemode & 0x01) === 0x00){ if($this->fallY === false or $this->fallStart === false){ $this->fallY = $y; $this->fallStart = microtime(true); @@ -375,7 +375,7 @@ class Entity extends stdClass{ if($this->class === ENTITY_PLAYER){ $this->calculateVelocity(); - if($this->speed <= 5 or ($this->speed <= 12 and $this->gamemode === CREATIVE)){ + if($this->speed <= 5 or ($this->speed <= 12 and ($player->gamemode & 0x01) === 0x01)){ $this->player->lastCorrect = new Vector3($this->last[0], $this->last[1], $this->last[2]); } } @@ -634,7 +634,7 @@ class Entity extends stdClass{ if($health < $this->health){ $harm = true; $dmg = $this->health - $health; - if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and ($this->player->gamemode === SURVIVAL or $this->player->gamemode === ADVENTURE or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){ + if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and (($this->player->gamemode & 0x01) === 0x00 or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){ $this->dmgcounter[0] = microtime(true) + 0.5; $this->dmgcounter[1] = $dmg; }else{ diff --git a/src/world/generator/Generator.class.php b/src/world/generator/Generator.class.php index e3cd1771f..5ebc9d8b8 100644 --- a/src/world/generator/Generator.class.php +++ b/src/world/generator/Generator.class.php @@ -344,7 +344,7 @@ class WorldGenerator{ $level = array( "LevelName" => $name, "Time" => 0, - "Gamemode" => 1, + "Gamemode" => CREATIVE, "RandomSeed" => $this->seed, "Generator" => $this->genName, "SpawnX" => $s[0],