isEnabled()){ throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $this->permissible = $permissible; $this->plugin = $plugin; } public function getPlugin() : Plugin{ return $this->plugin; } /** * @return void */ public function setRemovalCallback(PermissionRemovedExecutor $ex){ $this->removed = $ex; } /** * @return PermissionRemovedExecutor|null */ public function getRemovalCallback(){ return $this->removed; } public function getPermissible() : Permissible{ return $this->permissible; } /** * @return bool[] */ public function getPermissions() : array{ return $this->permissions; } /** * @return void */ public function clearPermissions(){ $this->permissions = []; $this->permissible->recalculatePermissions(); } /** * @param bool[] $permissions * * @return void */ public function setPermissions(array $permissions){ foreach($permissions as $key => $value){ $this->permissions[$key] = $value; } $this->permissible->recalculatePermissions(); } /** * @param string[] $permissions * * @return void */ public function unsetPermissions(array $permissions){ foreach($permissions as $node){ unset($this->permissions[$node]); } $this->permissible->recalculatePermissions(); } /** * @param string|Permission $name * * @return void */ public function setPermission($name, bool $value){ $name = $name instanceof Permission ? $name->getName() : $name; if(isset($this->permissions[$name])){ if($this->permissions[$name] === $value){ return; } /* Because of the way child permissions are calculated, permissions which were set later in time are * preferred over earlier ones when conflicts in inherited permission values occur. * Here's the kicker: This behaviour depends on PHP's internal array ordering, which maintains insertion * order -- BUT -- assigning to an existing index replaces the old value WITHOUT changing the order. * (what crazy person thought relying on this this was a good idea?!?!?!?!?!) * * This removes the old value so that the new value will be added at the end of the array's internal order * instead of directly taking the place of the older value. */ unset($this->permissions[$name]); } $this->permissions[$name] = $value; $this->permissible->recalculatePermissions(); } /** * @param string|Permission $name * * @return void */ public function unsetPermission($name){ $name = $name instanceof Permission ? $name->getName() : $name; if(isset($this->permissions[$name])){ unset($this->permissions[$name]); $this->permissible->recalculatePermissions(); } } /** * @return void */ public function remove(){ $this->permissible->removeAttachment($this); } }