mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 20:14:31 +00:00
Implemented a better method for detecting permission recalculation
this allows anyone to listen to permissions being recalculated, which is useful for stuff like broadcast channel subscriptions.
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\permission;
|
||||
|
||||
use Ds\Set;
|
||||
use pocketmine\plugin\Plugin;
|
||||
|
||||
interface Permissible{
|
||||
@@ -67,6 +68,12 @@ interface Permissible{
|
||||
|
||||
public function recalculatePermissions() : void;
|
||||
|
||||
/**
|
||||
* @return Set|\Closure[]
|
||||
* @phpstan-return Set<\Closure() : void>
|
||||
*/
|
||||
public function getPermissionRecalculationCallbacks() : Set;
|
||||
|
||||
/**
|
||||
* @return PermissionAttachmentInfo[]
|
||||
*/
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\permission;
|
||||
|
||||
use Ds\Set;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\plugin\PluginException;
|
||||
use pocketmine\timings\Timings;
|
||||
@@ -46,7 +47,15 @@ class PermissibleBase implements Permissible{
|
||||
/** @var PermissionAttachmentInfo[] */
|
||||
private $permissions = [];
|
||||
|
||||
/**
|
||||
* @var Set|\Closure[]
|
||||
* @phpstan-var Set<\Closure() : void>
|
||||
*/
|
||||
private $permissionRecalculationCallbacks;
|
||||
|
||||
public function __construct(?Permissible $permissible, bool $isOp){
|
||||
$this->permissionRecalculationCallbacks = new Set();
|
||||
|
||||
$this->parent = $permissible;
|
||||
|
||||
//TODO: we can't setBasePermission here directly due to bad architecture that causes recalculatePermissions to explode
|
||||
@@ -149,6 +158,11 @@ class PermissibleBase implements Permissible{
|
||||
$this->calculateChildPermissions($attachment->getPermissions(), false, $attachment);
|
||||
}
|
||||
|
||||
foreach($this->permissionRecalculationCallbacks as $closure){
|
||||
//TODO: provide a diff of permissions
|
||||
$closure();
|
||||
}
|
||||
|
||||
Timings::$permissibleCalculationTimer->stopTiming();
|
||||
}
|
||||
|
||||
@@ -169,6 +183,12 @@ class PermissibleBase implements Permissible{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Closure[]|Set
|
||||
* @phpstan-return Set<\Closure() : void>
|
||||
*/
|
||||
public function getPermissionRecalculationCallbacks() : Set{ return $this->permissionRecalculationCallbacks; }
|
||||
|
||||
/**
|
||||
* @return PermissionAttachmentInfo[]
|
||||
*/
|
||||
@@ -181,5 +201,6 @@ class PermissibleBase implements Permissible{
|
||||
$this->permissions = []; //PermissionAttachmentInfo doesn't reference Permissible anymore, but it references PermissionAttachment which does
|
||||
$this->attachments = []; //this might still be a problem if the attachments are still referenced, but we can't do anything about that
|
||||
$this->parent = null;
|
||||
$this->permissionRecalculationCallbacks->clear();
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\permission;
|
||||
|
||||
use Ds\Set;
|
||||
use pocketmine\plugin\Plugin;
|
||||
|
||||
trait PermissibleDelegateTrait{
|
||||
@@ -70,6 +71,14 @@ trait PermissibleDelegateTrait{
|
||||
$this->perm->recalculatePermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set|\Closure[]
|
||||
* @phpstan-return Set<\Closure() : void>
|
||||
*/
|
||||
public function getPermissionRecalculationCallbacks() : Set{
|
||||
return $this->perm->getPermissionRecalculationCallbacks();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PermissionAttachmentInfo[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user