diff --git a/src/API/PermissionsAPI.php b/src/API/PermissionsAPI.php index 887ee3745..b48cdc438 100644 --- a/src/API/PermissionsAPI.php +++ b/src/API/PermissionsAPI.php @@ -49,19 +49,14 @@ class PermissionsAPI{ { ServerAPI::request()->api->addHandler("player.connect", function ($player)//Use a better event than player.connect. Player.create maybe? { + /** @var array $newPermission */ $newPermission = ServerAPI::request()->api->dhandle("permissions.request", array('player' => $player)); if($newPermission instanceof Permission){ - $player->permission = $newPermission;//This is a class with functions in it. So now plugins can call $player->permissions->isGranted(). + $player->permission = $newPermission;//This is a class with functions in it. So now plugins can call $player->permissions->isGranted(). Symfony2 Style! }else{ //TODO: Give out default permission. Fall back to OP system maybe? Checking for a permissions receiver would be nice. - $player->permission = new DefaultPermission(); } }, 1);//Experimental. Use Closure / Anonymous Functions to assign new functions from each API rather than hard-coding them to Player.php. - - ServerAPI::request()->api->addHandler("player.connect", function ($player) - { - - }, 1); } } @@ -78,36 +73,9 @@ interface Permission{ public function getPermissionLevel(); /** - * @param object $permission Permission to check the user for. Must be a an object implementing Permission class. + * @param Permission $permission Permission to check the user for. Must be a an object implementing Permission class. * * @return boolean Whether the person has permissions or not. */ public function isGranted($permission); -} - -class DefaultPermission implements Permission{//TODO: Remove this in the future for a better system than a default permission. - /** - * @var integer - */ - private $permissionLevel = 0;//Highest permission possible. - - /** - * @param Permission $permissionToCheckGranted - * - * @return boolean - */ - public function isGranted($permissionToCheckGranted){ - if($this->getPermissionLevel() >= $permissionToCheckGranted->getPermissionLevel()){ - return true; - }else{ - return false; - } - } - - /** - * @return integer - */ - public function getPermissionLevel(){ - return $this->permissionLevel; - } } \ No newline at end of file diff --git a/src/Player.php b/src/Player.php index 4c9938b09..207e63ca6 100644 --- a/src/Player.php +++ b/src/Player.php @@ -60,7 +60,7 @@ class Player{ public $blocked = true; public $achievements = array(); public $chunksLoaded = array(); - public $permission = false; + public $permissions = array(); private $chunksOrder = array(); private $lastMeasure = 0; private $bandwidthRaw = 0; @@ -672,8 +672,12 @@ class Player{ break; } } - - public function sendChat($message, $author = ""){ + + /** + * @param string $message + * @param string $author + */ + public function sendChat($message, $author = ""){ $mes = explode("\n", $message); foreach($mes as $m){ if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0){ @@ -752,8 +756,15 @@ class Player{ "flags" => $flags, )); } - - public function craftItems(array $craft, array $recipe, $type){ + + /** + * @param array $craft + * @param array $recipe + * @param $type + * + * @return array|bool + */ + public function craftItems(array $craft, array $recipe, $type){ $craftItem = array(0, true, 0); unset($craft[-1]); foreach($craft as $slot => $item){ @@ -846,8 +857,17 @@ class Player{ } return $res; } - - public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = true, $force = true){ + + /** + * @param Vector3 $pos + * @param float|boolean $yaw + * @param float|boolean $pitch + * @param float|boolean $terrain + * @param float|boolean $force + * + * @return boolean + */ + public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = true, $force = true){ if($this->entity instanceof Entity and $this->level instanceof Level){ $this->entity->check = false; if($yaw === false){ @@ -2122,8 +2142,11 @@ class Player{ break; } } - - public function sendArmor($player = false){ + + /** + * @param Player|string|boolean|void $player + */ + public function sendArmor($player = false){ $data = array( "player" => $this, "eid" => $this->eid @@ -2225,7 +2248,13 @@ class Player{ return array($count); } - public function dataPacket($id, $data = array()){ + /** + * @param integer $id + * @param array $data + * + * @return array|bool + */ + public function dataPacket($id, $data = array()){ $data["id"] = $id; if($id === false){ $raw = $data["raw"]; @@ -2245,8 +2274,11 @@ class Player{ $this->buffer .= ($this->buffer === "" ? "":"\x40").Utils::writeShort($len << 3).strrev(Utils::writeTriad($this->counter[3]++)).$raw; return array(); } - - function __toString(){ + + /** + * @return string + */ + function __toString(){ if($this->username != ""){ return $this->username; }