Fixed PermissibleBase->clearPermissions() not unsubscribing from permissions that aren't explicitly assigned

This came to light after observing cfb6856634f91930f6e013e7b98edb638dea15d9 in a fresh light. I noticed that this fix should not have been necessary because clearPermissions() should have dealt with it. Unfortunately, permissions can be set without being set in PermissibleBase->permissions, so this misses things.
This commit is contained in:
Dylan K. Taylor 2018-09-14 17:06:32 +01:00
parent bfbc845efa
commit 5863d4c066
2 changed files with 13 additions and 3 deletions

View File

@ -166,9 +166,7 @@ class PermissibleBase implements Permissible{
public function clearPermissions(){
$pluginManager = Server::getInstance()->getPluginManager();
foreach(array_keys($this->permissions) as $name){
$pluginManager->unsubscribeFromPermission($name, $this->parent ?? $this);
}
$pluginManager->unsubscribeFromAllPermissions($this->parent ?? $this);
$pluginManager->unsubscribeFromDefaultPerms(false, $this->parent ?? $this);
$pluginManager->unsubscribeFromDefaultPerms(true, $this->parent ?? $this);

View File

@ -534,6 +534,18 @@ class PluginManager{
}
}
/**
* @param Permissible $permissible
*/
public function unsubscribeFromAllPermissions(Permissible $permissible) : void{
foreach($this->permSubs as $permission => &$subs){
unset($subs[spl_object_hash($permissible)]);
if(empty($subs)){
unset($this->permSubs[$permission]);
}
}
}
/**
* @param string $permission
*