GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
PermissibleBase Class Reference

Public Member Functions

 __construct (ServerOperator $opable)
 
 __destruct ()
 
 isOp ()
 
 setOp ($value)
 
 isPermissionSet ($name)
 
 hasPermission ($name)
 
 addAttachment (Plugin $plugin, $name=null, $value=null)
 
 removeAttachment (PermissionAttachment $attachment)
 
 recalculatePermissions ()
 
 clearPermissions ()
 
 getEffectivePermissions ()
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( ServerOperator  $opable)
Parameters
ServerOperator$opable
49  {
50  $this->opable = $opable;
51  if($opable instanceof Permissible){
52  $this->parent = $opable;
53  }
54  }

◆ __destruct()

__destruct ( )
56  {
57  $this->parent = null;
58  $this->opable = null;
59  }

Member Function Documentation

◆ addAttachment()

addAttachment ( Plugin  $plugin,
  $name = null,
  $value = null 
)

//TODO: tick scheduled attachments

Parameters
Plugin$plugin
string$name
bool$value
Returns
PermissionAttachment
Exceptions
PluginException

Implements Permissible.

129  {
130  if($plugin === null){
131  throw new PluginException("Plugin cannot be null");
132  }elseif(!$plugin->isEnabled()){
133  throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
134  }
135 
136  $result = new PermissionAttachment($plugin, $this->parent !== null ? $this->parent : $this);
137  $this->attachments[spl_object_hash($result)] = $result;
138  if($name !== null and $value !== null){
139  $result->setPermission($name, $value);
140  }
141 
142  $this->recalculatePermissions();
143 
144  return $result;
145  }

◆ clearPermissions()

clearPermissions ( )
190  {
191  foreach(array_keys($this->permissions) as $name){
192  Server::getInstance()->getPluginManager()->unsubscribeFromPermission($name, $this->parent !== null ? $this->parent : $this);
193  }
194 
195  Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(false, $this->parent !== null ? $this->parent : $this);
196  Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(true, $this->parent !== null ? $this->parent : $this);
197 
198  $this->permissions = [];
199  }

◆ getEffectivePermissions()

getEffectivePermissions ( )
Returns
PermissionAttachmentInfo[]

Implements Permissible.

222  {
223  return $this->permissions;
224  }

◆ hasPermission()

hasPermission (   $name)
Parameters
Permission | string$name
Returns
bool

Implements Permissible.

99  {
100  if($name instanceof Permission){
101  $name = $name->getName();
102  }
103 
104  if($this->isPermissionSet($name)){
105  return $this->permissions[$name]->getValue();
106  }
107 
108  if(($perm = Server::getInstance()->getPluginManager()->getPermission($name)) !== null){
109  $perm = $perm->getDefault();
110 
111  return $perm === Permission::DEFAULT_TRUE or ($this->isOp() and $perm === Permission::DEFAULT_OP) or (!$this->isOp() and $perm === Permission::DEFAULT_NOT_OP);
112  }else{
114  }
115 
116  }

◆ isOp()

isOp ( )
Returns
bool

Implements ServerOperator.

64  {
65  if($this->opable === null){
66  return false;
67  }else{
68  return $this->opable->isOp();
69  }
70  }

◆ isPermissionSet()

isPermissionSet (   $name)
Parameters
Permission | string$name
Returns
bool

Implements Permissible.

90  {
91  return isset($this->permissions[$name instanceof Permission ? $name->getName() : $name]);
92  }

◆ recalculatePermissions()

recalculatePermissions ( )
Returns
void

Implements Permissible.

169  {
171 
172  $this->clearPermissions();
173  $defaults = Server::getInstance()->getPluginManager()->getDefaultPermissions($this->isOp());
174  Server::getInstance()->getPluginManager()->subscribeToDefaultPerms($this->isOp(), $this->parent !== null ? $this->parent : $this);
175 
176  foreach($defaults as $perm){
177  $name = $perm->getName();
178  $this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, null, true);
179  Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this);
180  $this->calculateChildPermissions($perm->getChildren(), false, null);
181  }
182 
183  foreach($this->attachments as $attachment){
184  $this->calculateChildPermissions($attachment->getPermissions(), false, $attachment);
185  }
186 
188  }

◆ removeAttachment()

removeAttachment ( PermissionAttachment  $attachment)
Parameters
PermissionAttachment$attachment
Exceptions

Implements Permissible.

152  {
153  if($attachment === null){
154  throw new \InvalidStateException("Attachment cannot be null");
155  }
156 
157  if(isset($this->attachments[spl_object_hash($attachment)])){
158  unset($this->attachments[spl_object_hash($attachment)]);
159  if(($ex = $attachment->getRemovalCallback()) !== null){
160  $ex->attachmentRemoved($attachment);
161  }
162 
163  $this->recalculatePermissions();
164 
165  }
166 
167  }

◆ setOp()

setOp (   $value)
Parameters
bool$value
Exceptions

Implements ServerOperator.

77  {
78  if($this->opable === null){
79  throw new \LogicException("Cannot change op value as no ServerOperator is set");
80  }else{
81  $this->opable->setOp($value);
82  }
83  }

The documentation for this class was generated from the following file: