diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 2a6294d0f..695055a46 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -154,10 +154,10 @@ class BlockAPI{ public function playerBlockBreak(Player $player, Vector3 $vector){ $target = $this->getBlock($vector); - if($target->isBreakable === false or $this->server->gamemode === 2){ - return $this->cancelAction($target); - } $item = $player->equipment; + if(!$target->isBreakable($item, $player) or $this->server->gamemode === 2){ + return $this->cancelAction($target); + } if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){ diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index d2e0af2ab..a4fcb89bf 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -135,7 +135,7 @@ class ServerAPI{ console("[NOTICE] \x1b[33mA new DEVELOPMENT version of PocketMine-MP has been released"); console("[NOTICE] \x1b[33mVersion \"".$info["development"]["version"]."\" [".substr($info["development"]["commit"], 0, 10)."]"); console("[NOTICE] \x1b[36mIf you want to update, get the latest version at ".$info["development"]["download"]); - console("[NOTICE] This message will dissapear when you issue the command \"/update-done\""); + console("[NOTICE] This message will dissapear after issuing the command \"/update-done\""); sleep(3); }else{ $this->setProperty("last-update", time()); diff --git a/src/classes/Player.php b/src/classes/Player.php index 456af5a6c..5874af2a6 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -49,6 +49,7 @@ class Player{ public $equipment; var $armor = array(0, 0, 0, 0); var $loggedIn = false; + public $gamemode; private $chunksLoaded = array(); private $chunksOrder = array(); @@ -61,7 +62,8 @@ class Player{ $this->port = $port; $this->timeout = microtime(true) + 20; $this->inventory = array_fill(0, 36, array(AIR, 0, 0)); - if($this->server->gamemode === 0 or $this->server->gamemode === 2){ + $this->gamemode = $this->server->gamemode; + if($this->gamemode === 0 or $this->gamemode === 2){ $this->equipment = BlockAPI::getItem(AIR); }else{ $this->equipment = BlockAPI::getItem(STONE); @@ -272,14 +274,14 @@ class Player{ } break; case "player.block.place": - if($data["eid"] === $this->eid and ($this->server->gamemode === 0 or $this->server->gamemode === 2)){ + if($data["eid"] === $this->eid and ($this->gamemode === 0 or $this->gamemode === 2)){ $this->removeItem($data["original"]->getID(), $data["original"]->getMetadata(), 1); } break; case "player.pickup": if($data["eid"] === $this->eid){ $data["eid"] = 0; - if(($this->server->gamemode === 0 or $this->server->gamemode === 2)){ + if(($this->gamemode === 0 or $this->gamemode === 2)){ $this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack); } } @@ -517,7 +519,7 @@ class Player{ } $this->server->api->player->add($this->CID); $this->auth = true; - if(!isset($this->data["inventory"]) or $this->server->gamemode === 1){ + if(!isset($this->data["inventory"]) or $this->gamemode === 1){ $this->data["inventory"] = $this->inventory; } $this->inventory = &$this->data["inventory"]; @@ -535,7 +537,7 @@ class Player{ "y" => $this->data["spawn"]["y"], "z" => $this->data["spawn"]["z"], "unknown1" => 0, - "gamemode" => $this->server->gamemode, + "gamemode" => $this->gamemode, "eid" => 0, )); break; @@ -600,7 +602,7 @@ class Player{ 0x80 ? */ $flags = 0; - if($this->server->gamemode === 2){ + if($this->gamemode === 2){ $flags |= 0x01; //Not allow placing/breaking blocks } $flags |= 0x20; //Nametags @@ -632,7 +634,7 @@ class Player{ $data["eid"] = $this->eid; if(Utils::distance($this->entity->position, $data) > 10){ break; - }elseif(($this->server->gamemode === 0 or $this->server->gamemode === 2) and !$this->hasItem($data["block"], $data["meta"])){ + }elseif(($this->gamemode === 0 or $this->gamemode === 2) and !$this->hasItem($data["block"], $data["meta"])){ console("[DEBUG] Player \"".$this->username."\" tried to place not got block (or crafted block)", true, true, 2); //break; } @@ -672,7 +674,7 @@ class Player{ $this->entity->updateMetadata(); break; case MC_SET_HEALTH: - if($this->server->gamemode === 1){ + if($this->gamemode === 1){ break; } //$this->entity->setHealth($data["health"], "client"); diff --git a/src/classes/material/Block.php b/src/classes/material/Block.php index fc50e97bf..49717992e 100644 --- a/src/classes/material/Block.php +++ b/src/classes/material/Block.php @@ -138,7 +138,7 @@ abstract class Block{ protected $shortname = ""; protected $name = ""; public $isActivable = false; - public $isBreakable = true; + public $breakable = true; public $isFlowable = false; public $isTransparent = false; public $isReplaceable = false; @@ -186,6 +186,8 @@ abstract class Block{ } } + abstract function isBreakable(Item $item, Player $player); + abstract function onBreak(BlockAPI $level, Item $item, Player $player); abstract function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz); diff --git a/src/classes/material/block/GenericBlock.php b/src/classes/material/block/GenericBlock.php index aba1b9336..bc5493503 100644 --- a/src/classes/material/block/GenericBlock.php +++ b/src/classes/material/block/GenericBlock.php @@ -38,6 +38,10 @@ class GenericBlock extends Block{ return false; } + public function isBreakable(Item $item, Player $player){ + return $this->breakable; + } + public function onBreak(BlockAPI $level, Item $item, Player $player){ if($this->inWorld === true){ $level->setBlock($this, AIR, 0); diff --git a/src/classes/material/block/LiquidBlock.php b/src/classes/material/block/LiquidBlock.php index 8766d63de..67f320fae 100644 --- a/src/classes/material/block/LiquidBlock.php +++ b/src/classes/material/block/LiquidBlock.php @@ -29,7 +29,7 @@ class LiquidBlock extends TransparentBlock{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); $this->isLiquid = true; - $this->isBreakable = false; + $this->breakable = false; $this->isReplaceable = true; } } \ No newline at end of file diff --git a/src/classes/material/block/TransparentBlock.php b/src/classes/material/block/TransparentBlock.php index 86271f9b8..1e89de1e2 100644 --- a/src/classes/material/block/TransparentBlock.php +++ b/src/classes/material/block/TransparentBlock.php @@ -29,7 +29,7 @@ class TransparentBlock extends GenericBlock{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); $this->isActivable = false; - $this->isBreakable = true; + $this->breakable = true; $this->isFlowable = false; $this->isTransparent = true; $this->isReplaceable = false; diff --git a/src/classes/material/block/misc/Air.php b/src/classes/material/block/misc/Air.php index c33e54cab..e874f0b83 100644 --- a/src/classes/material/block/misc/Air.php +++ b/src/classes/material/block/misc/Air.php @@ -29,7 +29,7 @@ class AirBlock extends TransparentBlock{ public function __construct(){ parent::__construct(AIR, 0, "Air"); $this->isActivable = false; - $this->isBreakable = false; + $this->breakable = false; $this->isFlowable = true; $this->isTransparent = true; $this->isReplaceable = true; diff --git a/src/classes/material/block/misc/Fire.php b/src/classes/material/block/misc/Fire.php index 756cd8032..358561186 100644 --- a/src/classes/material/block/misc/Fire.php +++ b/src/classes/material/block/misc/Fire.php @@ -29,7 +29,7 @@ class FireBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(FIRE, $meta, "Fire"); $this->isReplaceable = true; - $this->isBreakable = false; + $this->breakable = false; } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Bedrock.php b/src/classes/material/block/solid/Bedrock.php index 3b6c02d89..9487c26be 100644 --- a/src/classes/material/block/solid/Bedrock.php +++ b/src/classes/material/block/solid/Bedrock.php @@ -28,7 +28,14 @@ the Free Software Foundation, either version 3 of the License, or class BedrockBlock extends SolidBlock{ public function __construct(){ parent::__construct(BEDROCK, 0, "Bedrock"); - $this->isBreakable = true;//$this->isBreakable = false; + $this->breakable = false; + } + + public function isBreakable(Item $item, Player $player){ + if($player->gamemode === 1){ + return true; + } + return false; } } \ No newline at end of file