mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 19:55:33 +00:00
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:
parent
5ac0907aeb
commit
e6f855abbd
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user