Fixed Permissible::setPermission() not using the correct order on replacement

This commit is contained in:
Shoghi Cervantes 2014-09-11 12:17:03 +02:00
parent fba12c6ddf
commit 4624dfb472
3 changed files with 9 additions and 4 deletions

View File

@ -194,10 +194,10 @@ class PermissibleBase implements Permissible{
* @param bool $invert
* @param PermissionAttachment $attachment
*/
public function calculateChildPermissions(array $children, $invert, $attachment){
foreach(array_keys($children) as $name){
private function calculateChildPermissions(array $children, $invert, $attachment){
foreach($children as $name => $v){
$perm = Server::getInstance()->getPluginManager()->getPermission($name);
$value = $invert === true ? !$children[$name] : $children[$name];
$value = ($v xor $invert);
$this->permissions[$name] = new PermissionAttachmentInfo($this->parent, $name, $attachment, $value);
Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent);

View File

@ -93,7 +93,9 @@ class PermissionAttachment{
* @param bool $value
*/
public function setPermission($name, $value){
$this->permissions[$name instanceof Permission ? $name->getName() : $name] = $value;
$name = $name instanceof Permission ? $name->getName() : $name;
unset($this->permissions[$name]); //Fixes children getting overwritten
$this->permissions[$name] = $value;
$this->permissible->recalculatePermissions();
}

View File

@ -434,6 +434,9 @@ class PluginManager{
public function unsubscribeFromPermission($permission, Permissible $permissible){
if(isset($this->permSubs[$permission])){
unset($this->permSubs[$permission][spl_object_hash($permissible)]);
if(count($this->permSubs[$permission]) === 0){
unset($this->permSubs[$permission]);
}
}
}