From 5863d4c066d6a778ce190567616c9f4bc0a78d9a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Sep 2018 17:06:32 +0100 Subject: [PATCH] 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. --- src/pocketmine/permission/PermissibleBase.php | 4 +--- src/pocketmine/plugin/PluginManager.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index bec0fab46..a41da057f 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -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); diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index df0e3afb9..e11af6efe 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -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 *