From 544d99f161affa876a884d887844878cdfaeef92 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 12 Dec 2016 10:07:34 +0000 Subject: [PATCH] Added ability to force literal gamemode checks for Player->isSurvival(), Player->isCreative() and Player->isAdventure() (#155) --- src/pocketmine/Player.php | 50 +++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index e59d256291..21aaa1392c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1186,28 +1186,58 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } /** - * WARNING: This method does NOT return literal gamemode is survival, it will also return true for adventure mode players. + * NOTE: Because Survival and Adventure Mode share some similar behaviour, this method will also return true if the player is + * in Adventure Mode. Supply the $literal parameter as true to force a literal Survival Mode check. + * + * @param bool $literal whether a literal check should be performed + * + * @return bool */ - public function isSurvival() : bool{ - return ($this->gamemode & 0x01) === 0; + public function isSurvival(bool $literal = false) : bool{ + if($literal){ + return $this->gamemode === Player::SURVIVAL; + }else{ + return ($this->gamemode & 0x01) === 0; + } } /** - * WARNING: This method does NOT return literal gamemode is creative, it will also return true for spectator mode players. + * NOTE: Because Creative and Spectator Mode share some similar behaviour, this method will also return true if the player is + * in Spectator Mode. Supply the $literal parameter as true to force a literal Creative Mode check. + * + * @param bool $literal whether a literal check should be performed + * + * @return bool */ - public function isCreative() : bool{ - return ($this->gamemode & 0x01) === 1; + public function isCreative(bool $literal = false) : bool{ + if($literal){ + return $this->gamemode === Player::CREATIVE; + }else{ + return ($this->gamemode & 0x01) === 1; + } } /** - * WARNING: This method does NOT return literal gamemode is adventure, it will also return true for spectator mode players. + * NOTE: Because Adventure and Spectator Mode share some similar behaviour, this method will also return true if the player is + * in Spectator Mode. Supply the $literal parameter as true to force a literal Adventure Mode check. + * + * @param bool $literal whether a literal check should be performed + * + * @return bool */ - public function isAdventure() : bool{ - return ($this->gamemode & 0x02) > 0; + public function isAdventure(bool $literal = false) : bool{ + if($literal){ + return $this->gamemode === Player::ADVENTURE; + }else{ + return ($this->gamemode & 0x02) > 0; + } } + /** + * @return bool + */ public function isSpectator() : bool{ - return $this->gamemode === 3; + return $this->gamemode === Player::SPECTATOR; } public function getDrops(){