Add Default permission, and remove construct restriction in Permission interface. Note that all changes on permission API are untested therefore not enabled by default.

This commit is contained in:
Michael Yoo 2013-11-25 20:11:38 +10:30
parent 5ac0907aeb
commit e6f855abbd
2 changed files with 44 additions and 13 deletions

View File

@ -48,13 +48,16 @@ class PermissionsAPI{
/** /**
* @access public * @access public
*/ */
public function init(){ public function init()
ServerAPI::request()->api->addHandler("player.connect", function ($player){//Use a better event than player.connect. Player.create maybe? {
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(). $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{ }else{
//TODO: Give out default permission. Fall back to OP system maybe? Checking for a permissions receiver would be nice. //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. }, 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(); public function getPermissionLevel();
/** /**
* @param integer $permissionLevel Integer based value of permission. * @param object $permission Permission to check the user for. Must be a an object implementing Permission class.
*/
public function __construct($permissionLevel);
/**
* @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. * @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;
}
} }

View File

@ -60,7 +60,7 @@ class Player{
public $blocked = true; public $blocked = true;
public $achievements = array(); public $achievements = array();
public $chunksLoaded = array(); public $chunksLoaded = array();
public $permissions = false; public $permission = false;
private $chunksOrder = array(); private $chunksOrder = array();
private $lastMeasure = 0; private $lastMeasure = 0;
private $bandwidthRaw = 0; private $bandwidthRaw = 0;