mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
PermissionAttachmentInfo now includes a reference to the PermissionAttachmentInfo that caused its assignment (if any)
this allows plugins to easily identify which permission group caused a permission to be assigned (particularly if multiple groups might cause it).
This commit is contained in:
parent
880635603c
commit
506e76917e
@ -146,13 +146,13 @@ class PermissibleBase implements Permissible{
|
||||
if($perm === null){
|
||||
throw new \InvalidStateException("Unregistered root permission $name");
|
||||
}
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($name, null, $isGranted);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($name, null, $isGranted, null);
|
||||
$permManager->subscribeToPermission($name, $this);
|
||||
$this->calculateChildPermissions($perm->getChildren(), !$isGranted, null);
|
||||
$this->calculateChildPermissions($perm->getChildren(), !$isGranted, null, $this->permissions[$name]);
|
||||
}
|
||||
|
||||
foreach($this->attachments as $attachment){
|
||||
$this->calculateChildPermissions($attachment->getPermissions(), false, $attachment);
|
||||
$this->calculateChildPermissions($attachment->getPermissions(), false, $attachment, null);
|
||||
}
|
||||
|
||||
$diff = [];
|
||||
@ -189,16 +189,16 @@ class PermissibleBase implements Permissible{
|
||||
/**
|
||||
* @param bool[] $children
|
||||
*/
|
||||
private function calculateChildPermissions(array $children, bool $invert, ?PermissionAttachment $attachment) : void{
|
||||
private function calculateChildPermissions(array $children, bool $invert, ?PermissionAttachment $attachment, ?PermissionAttachmentInfo $parent) : void{
|
||||
$permManager = PermissionManager::getInstance();
|
||||
foreach($children as $name => $v){
|
||||
$perm = $permManager->getPermission($name);
|
||||
$value = ($v xor $invert);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($name, $attachment, $value);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($name, $attachment, $value, $parent);
|
||||
$permManager->subscribeToPermission($name, $this);
|
||||
|
||||
if($perm instanceof Permission){
|
||||
$this->calculateChildPermissions($perm->getChildren(), !$value, $attachment);
|
||||
$this->calculateChildPermissions($perm->getChildren(), !$value, $attachment, $this->permissions[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,14 @@ class PermissionAttachmentInfo{
|
||||
/** @var bool */
|
||||
private $value;
|
||||
|
||||
public function __construct(string $permission, ?PermissionAttachment $attachment, bool $value){
|
||||
/** @var PermissionAttachmentInfo|null */
|
||||
private $groupPermission;
|
||||
|
||||
public function __construct(string $permission, ?PermissionAttachment $attachment, bool $value, ?PermissionAttachmentInfo $groupPermission){
|
||||
$this->permission = $permission;
|
||||
$this->attachment = $attachment;
|
||||
$this->value = $value;
|
||||
$this->groupPermission = $groupPermission;
|
||||
}
|
||||
|
||||
public function getPermission() : string{
|
||||
@ -50,4 +54,10 @@ class PermissionAttachmentInfo{
|
||||
public function getValue() : bool{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the info of the permission group that caused this permission to be set, if any.
|
||||
* If null, the permission was set explicitly, either by a permission attachment or base permission.
|
||||
*/
|
||||
public function getGroupPermissionInfo() : ?PermissionAttachmentInfo{ return $this->groupPermission; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user