PermissibleBase: allow injecting more dynamic base permissions

This commit is contained in:
Dylan K. Taylor 2020-12-02 10:12:40 +00:00
parent 13e8854ec0
commit 880635603c
3 changed files with 11 additions and 5 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\command;
use pocketmine\lang\Language;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissions;
use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissibleDelegateTrait;
use pocketmine\Server;
@ -44,7 +45,7 @@ class ConsoleCommandSender implements CommandSender{
public function __construct(Server $server, Language $language){
$this->server = $server;
$this->perm = new PermissibleBase(true);
$this->perm = new PermissibleBase([DefaultPermissions::ROOT_OPERATOR => true]);
$this->language = $language;
}

View File

@ -51,13 +51,17 @@ class PermissibleBase implements Permissible{
*/
private $permissionRecalculationCallbacks;
public function __construct(bool $isOp){
/**
* @param bool[] $basePermissions
* @phpstan-param array<string, bool> $basePermissions
*/
public function __construct(array $basePermissions){
$this->permissionRecalculationCallbacks = new Set();
//TODO: we can't setBasePermission here directly due to bad architecture that causes recalculatePermissions to explode
//so, this hack has to be done here to prevent permission recalculations until it's fixed...
if($isOp){
$this->rootPermissions[DefaultPermissions::ROOT_OPERATOR] = true;
foreach($basePermissions as $permission => $isGranted){
$this->rootPermissions[$permission] = $isGranted;
}
//TODO: permissions need to be recalculated here, or inherited permissions won't work
}

View File

@ -95,6 +95,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\entity\PlayerMetadataFlags;
use pocketmine\permission\DefaultPermissions;
use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissibleDelegateTrait;
use pocketmine\Server;
@ -278,7 +279,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->uuid = $this->playerInfo->getUuid();
$this->xuid = $this->playerInfo instanceof XboxLivePlayerInfo ? $this->playerInfo->getXuid() : "";
$this->perm = new PermissibleBase($this->server->isOp($this->username));
$this->perm = new PermissibleBase($this->server->isOp($this->username) ? [DefaultPermissions::ROOT_OPERATOR => true] : [DefaultPermissions::ROOT_USER => true]);
$this->chunksPerTick = (int) $this->server->getConfigGroup()->getProperty("chunk-sending.per-tick", 4);
$this->spawnThreshold = (int) (($this->server->getConfigGroup()->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
$this->chunkSelector = new ChunkSelector();