diff --git a/src/API/PermissionsAPI.php b/src/API/PermissionsAPI.php index f21844b75..5615c3830 100644 --- a/src/API/PermissionsAPI.php +++ b/src/API/PermissionsAPI.php @@ -48,13 +48,16 @@ class PermissionsAPI{ /** * @access public */ - public function init(){ - ServerAPI::request()->api->addHandler("player.connect", function ($player){//Use a better event than player.connect. Player.create maybe? - - if($permission = ServerAPI::request()->api->dhandle("permissions.request", array('player' => $player)) instanceof Permission){ - $player->permissions = $permission;//This is a class with functions in it. So now plugins can call $player->permissions->isGranted(). + public function init() + { + ServerAPI::request()->api->addHandler("player.connect", function ($player)//Use a better event than player.connect. Player.create maybe? + { + $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(). }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. } @@ -73,14 +76,42 @@ interface Permission{ public function getPermissionLevel(); /** - * @param integer $permissionLevel Integer based value of permission. - */ - public function __construct($permissionLevel); - - /** - * @param Permission $permission Permission to check the user for. Must be a an object implementing Permission class. + * @param object $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 static function isGranted($permission); + 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 70b622873..b660fc2c5 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 $permissions = false; + public $permission = false; private $chunksOrder = array(); private $lastMeasure = 0; private $bandwidthRaw = 0;