mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 21:35:21 +00:00
New VIEW gamemode
This commit is contained in:
parent
5848d283da
commit
3577667039
@ -256,7 +256,7 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
if($player->gamemode === CREATIVE){
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
$output .= "Player is in creative mode.\n";
|
$output .= "Player is in creative mode.\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -283,6 +283,9 @@ class BlockAPI{
|
|||||||
"block" => $block->getID(),
|
"block" => $block->getID(),
|
||||||
"meta" => $block->getMetadata()
|
"meta" => $block->getMetadata()
|
||||||
));
|
));
|
||||||
|
if($player->itemEnforcement === true){
|
||||||
|
$player->sendInventory();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +298,7 @@ class BlockAPI{
|
|||||||
return $this->cancelAction($target, $player);
|
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);
|
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){
|
foreach($drops as $drop){
|
||||||
$this->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF));
|
$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);
|
return $this->cancelAction($block, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +405,7 @@ class BlockAPI{
|
|||||||
$t->data["creator"] = $player->username;
|
$t->data["creator"] = $player->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($player->gamemode !== CREATIVE){
|
if(($player->gamemode & 0x01) === 0x00){
|
||||||
$player->removeItem($item->getID(), $item->getMetadata(), 1);
|
$player->removeItem($item->getID(), $item->getMetadata(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,11 @@ class PlayerAPI{
|
|||||||
"2" => ADVENTURE,
|
"2" => ADVENTURE,
|
||||||
"adventure" => ADVENTURE,
|
"adventure" => ADVENTURE,
|
||||||
"a" => ADVENTURE,
|
"a" => ADVENTURE,
|
||||||
|
"3" => VIEW,
|
||||||
|
"view" => VIEW,
|
||||||
|
"viewer" => VIEW,
|
||||||
|
"spectator" => VIEW,
|
||||||
|
"v" => VIEW,
|
||||||
);
|
);
|
||||||
if($issuer instanceof Player){
|
if($issuer instanceof Player){
|
||||||
$player = $issuer;
|
$player = $issuer;
|
||||||
@ -328,7 +333,7 @@ class PlayerAPI{
|
|||||||
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
|
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
|
||||||
$data->save();
|
$data->save();
|
||||||
}
|
}
|
||||||
if($this->server->gamemode === CREATIVE){
|
if(($this->server->gamemode & 0x01) === 0x01){
|
||||||
$data->set("health", 20);
|
$data->set("health", 20);
|
||||||
}
|
}
|
||||||
$this->server->handle("player.offline.get", $data);
|
$this->server->handle("player.offline.get", $data);
|
||||||
|
@ -275,7 +275,7 @@ class Player{
|
|||||||
|
|
||||||
public function sendInventorySlot($s){
|
public function sendInventorySlot($s){
|
||||||
$s = (int) $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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ class Player{
|
|||||||
if($data["eid"] === $this->eid){
|
if($data["eid"] === $this->eid){
|
||||||
$data["eid"] = 0;
|
$data["eid"] = 0;
|
||||||
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
|
$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);
|
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -491,8 +491,8 @@ class Player{
|
|||||||
0x80000000 ?
|
0x80000000 ?
|
||||||
*/
|
*/
|
||||||
$flags = 0;
|
$flags = 0;
|
||||||
if($this->gamemode === ADVENTURE){
|
if(($this->gamemode & 0x02) === 0x02){
|
||||||
$flags |= 0x01; //Not allow placing/breaking blocks
|
$flags |= 0x01; //Not allow placing/breaking blocks, adventure mode
|
||||||
}
|
}
|
||||||
|
|
||||||
if($nametags !== false){
|
if($nametags !== false){
|
||||||
@ -542,17 +542,26 @@ class Player{
|
|||||||
return "creative";
|
return "creative";
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return "adventure";
|
return "adventure";
|
||||||
|
case VIEW:
|
||||||
|
return "view";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setGamemode($gm){
|
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;
|
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->gamemode = $gm;
|
||||||
$this->sendSettings();
|
$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");
|
$this->eventHandler("Your gamemode has been changed to ".$this->getGamemode().".", "server.chat");
|
||||||
}else{
|
}else{
|
||||||
$this->blocked = true;
|
$this->blocked = true;
|
||||||
@ -741,12 +750,18 @@ class Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->auth = true;
|
$this->auth = true;
|
||||||
if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){
|
if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){
|
||||||
if($this->gamemode === CREATIVE){
|
if(($this->gamemode & 0x01) === 0x01){
|
||||||
$this->itemEnforcement = true;
|
$this->itemEnforcement = true;
|
||||||
$this->inventory = array();
|
$this->inventory = array();
|
||||||
foreach(BlockAPI::$creative as $item){
|
if(($this->gamemode & 0x02) === 0x02){
|
||||||
$this->inventory[] = array($item[0], $item[1], 1);
|
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);
|
$this->data->set("inventory", $this->inventory);
|
||||||
@ -773,8 +788,8 @@ class Player{
|
|||||||
"gamemode" => $this->gamemode,
|
"gamemode" => $this->gamemode,
|
||||||
"eid" => 0,
|
"eid" => 0,
|
||||||
));
|
));
|
||||||
if($this->gamemode === CREATIVE){
|
if(($this->gamemode & 0x01) === 0x01){
|
||||||
$this->equipment = BlockAPI::getItem(STONE);
|
$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->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this));
|
||||||
$this->eid = $this->entity->eid;
|
$this->eid = $this->entity->eid;
|
||||||
@ -844,7 +859,7 @@ class Player{
|
|||||||
if(($this->entity instanceof Entity) and $data["counter"] > $this->lastMovement){
|
if(($this->entity instanceof Entity) and $data["counter"] > $this->lastMovement){
|
||||||
$this->lastMovement = $data["counter"];
|
$this->lastMovement = $data["counter"];
|
||||||
$speed = $this->entity->getSpeed();
|
$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){
|
if($this->lastCorrect instanceof Vector3){
|
||||||
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
|
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
|
||||||
}
|
}
|
||||||
@ -908,7 +923,7 @@ class Player{
|
|||||||
$data["entity"] = $this->entity;
|
$data["entity"] = $this->entity;
|
||||||
if(!($target instanceof Entity)){
|
if(!($target instanceof Entity)){
|
||||||
break;
|
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;
|
break;
|
||||||
}elseif($this->handle("player.interact", $data) !== false){
|
}elseif($this->handle("player.interact", $data) !== false){
|
||||||
switch($this->equipment->getID()){
|
switch($this->equipment->getID()){
|
||||||
@ -1000,7 +1015,7 @@ class Player{
|
|||||||
if($this->spawned === false){
|
if($this->spawned === false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($this->gamemode === CREATIVE){
|
if(($this->gamemode & 0x01) === 0x01){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//$this->entity->setHealth($data["health"], "client");
|
//$this->entity->setHealth($data["health"], "client");
|
||||||
|
@ -291,6 +291,8 @@ class PocketMinecraftServer{
|
|||||||
return "creative";
|
return "creative";
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return "adventure";
|
return "adventure";
|
||||||
|
case VIEW:
|
||||||
|
return "view";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +517,7 @@ class PocketMinecraftServer{
|
|||||||
$data[0],
|
$data[0],
|
||||||
$this->serverID,
|
$this->serverID,
|
||||||
RAKNET_MAGIC,
|
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"]);
|
), false, $packet["ip"], $packet["port"]);
|
||||||
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
||||||
break;
|
break;
|
||||||
|
@ -29,3 +29,4 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
define("SURVIVAL", 0);
|
define("SURVIVAL", 0);
|
||||||
define("CREATIVE", 1);
|
define("CREATIVE", 1);
|
||||||
define("ADVENTURE", 2);
|
define("ADVENTURE", 2);
|
||||||
|
define("VIEW", 3);
|
@ -191,7 +191,7 @@ abstract class Block extends Vector3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBreakTime(Item $item, Player $player){
|
public function getBreakTime(Item $item, Player $player){
|
||||||
if($player->gamemode === CREATIVE){
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
return 0.25;
|
return 0.25;
|
||||||
}
|
}
|
||||||
return $this->breakTime;
|
return $this->breakTime;
|
||||||
|
@ -32,7 +32,7 @@ class BedrockBlock extends SolidBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isBreakable(Item $item, Player $player){
|
public function isBreakable(Item $item, Player $player){
|
||||||
if($player->gamemode === CREATIVE){
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -60,7 +60,7 @@ class PaintingItem extends Item{
|
|||||||
$server = ServerAPI::request();
|
$server = ServerAPI::request();
|
||||||
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||||
$server->api->entity->spawnToAll($e->eid);
|
$server->api->entity->spawnToAll($e->eid);
|
||||||
if($player->gamemode !== CREATIVE){
|
if(($player->gamemode & 0x01) === 0x00){
|
||||||
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -194,7 +194,7 @@ class Entity extends stdClass{
|
|||||||
}else{
|
}else{
|
||||||
return false;
|
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(
|
if($this->server->api->dhandle("player.pickup", array(
|
||||||
"eid" => $player->eid,
|
"eid" => $player->eid,
|
||||||
"player" => $player,
|
"player" => $player,
|
||||||
@ -346,7 +346,7 @@ class Entity extends stdClass{
|
|||||||
//$this->server->api->handle("entity.motion", $this);
|
//$this->server->api->handle("entity.motion", $this);
|
||||||
}
|
}
|
||||||
}elseif($this->class === ENTITY_PLAYER){
|
}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){
|
if($this->fallY === false or $this->fallStart === false){
|
||||||
$this->fallY = $y;
|
$this->fallY = $y;
|
||||||
$this->fallStart = microtime(true);
|
$this->fallStart = microtime(true);
|
||||||
@ -375,7 +375,7 @@ class Entity extends stdClass{
|
|||||||
|
|
||||||
if($this->class === ENTITY_PLAYER){
|
if($this->class === ENTITY_PLAYER){
|
||||||
$this->calculateVelocity();
|
$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]);
|
$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){
|
if($health < $this->health){
|
||||||
$harm = true;
|
$harm = true;
|
||||||
$dmg = $this->health - $health;
|
$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[0] = microtime(true) + 0.5;
|
||||||
$this->dmgcounter[1] = $dmg;
|
$this->dmgcounter[1] = $dmg;
|
||||||
}else{
|
}else{
|
||||||
|
@ -344,7 +344,7 @@ class WorldGenerator{
|
|||||||
$level = array(
|
$level = array(
|
||||||
"LevelName" => $name,
|
"LevelName" => $name,
|
||||||
"Time" => 0,
|
"Time" => 0,
|
||||||
"Gamemode" => 1,
|
"Gamemode" => CREATIVE,
|
||||||
"RandomSeed" => $this->seed,
|
"RandomSeed" => $this->seed,
|
||||||
"Generator" => $this->genName,
|
"Generator" => $this->genName,
|
||||||
"SpawnX" => $s[0],
|
"SpawnX" => $s[0],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user