PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
PermissionAttachment.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\permission;
23 
26 
29  private $removed = null;
30 
34  private $permissions = [];
35 
37  private $permissible;
38 
40  private $plugin;
41 
48  public function __construct(Plugin $plugin, Permissible $permissible){
49  if(!$plugin->isEnabled()){
50  throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
51  }
52 
53  $this->permissible = $permissible;
54  $this->plugin = $plugin;
55  }
56 
60  public function getPlugin(){
61  return $this->plugin;
62  }
63 
68  $this->removed = $ex;
69  }
70 
74  public function getRemovalCallback(){
75  return $this->removed;
76  }
77 
81  public function getPermissible(){
82  return $this->permissible;
83  }
84 
88  public function getPermissions(){
89  return $this->permissions;
90  }
91 
95  public function clearPermissions(){
96  $this->permissions = [];
97  $this->permissible->recalculatePermissions();
98  }
99 
103  public function setPermissions(array $permissions){
104  foreach($permissions as $key => $value){
105  $this->permissions[$key] = (bool) $value;
106  }
107  $this->permissible->recalculatePermissions();
108  }
109 
113  public function unsetPermissions(array $permissions){
114  foreach($permissions as $node){
115  unset($this->permissions[$node]);
116  }
117  $this->permissible->recalculatePermissions();
118  }
119 
124  public function setPermission($name, $value){
125  $name = $name instanceof Permission ? $name->getName() : $name;
126  if(isset($this->permissions[$name])){
127  if($this->permissions[$name] === $value){
128  return;
129  }
130  unset($this->permissions[$name]); //Fixes children getting overwritten
131  }
132  $this->permissions[$name] = $value;
133  $this->permissible->recalculatePermissions();
134  }
135 
139  public function unsetPermission($name){
140  $name = $name instanceof Permission ? $name->getName() : $name;
141  if(isset($this->permissions[$name])){
142  unset($this->permissions[$name]);
143  $this->permissible->recalculatePermissions();
144  }
145  }
146 
150  public function remove(){
151  $this->permissible->removeAttachment($this);
152  }
153 }
__construct(Plugin $plugin, Permissible $permissible)
setRemovalCallback(PermissionRemovedExecutor $ex)