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

Public Member Functions

 __construct ($name, $description=null, $defaultValue=null, array $children=[])
 
 getName ()
 
getChildren ()
 
 getDefault ()
 
 setDefault ($value)
 
 getDescription ()
 
 setDescription ($value)
 
 getPermissibles ()
 
 recalculatePermissibles ()
 
 addParent ($name, $value)
 

Static Public Member Functions

static getByName ($value)
 
static loadPermissions (array $data, $default=self::DEFAULT_OP)
 
static loadPermission ($name, array $data, $default=self::DEFAULT_OP, &$output=[])
 

Data Fields

const DEFAULT_OP = "op"
 
const DEFAULT_NOT_OP = "notop"
 
const DEFAULT_TRUE = "true"
 
const DEFAULT_FALSE = "false"
 

Static Public Attributes

static $DEFAULT_PERMISSION = self::DEFAULT_OP
 

Detailed Description

Represents a permission

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
  $description = null,
  $defaultValue = null,
array  $children = [] 
)

Creates a new Permission object to be attached to Permissible objects

Parameters
string$name
string$description
string$defaultValue
Permission[]$children
101  {
102  $this->name = $name;
103  $this->description = $description !== null ? $description : "";
104  $this->defaultValue = $defaultValue !== null ? $defaultValue : self::$DEFAULT_PERMISSION;
105  $this->children = $children;
106 
107  $this->recalculatePermissibles();
108  }

Member Function Documentation

◆ addParent()

addParent (   $name,
  $value 
)
Parameters
string | Permission$name
$value
Returns
Permission|null Permission if $name is a string, void if it's a Permission
179  {
180  if($name instanceof Permission){
181  $name->getChildren()[$this->getName()] = $value;
182  $name->recalculatePermissibles();
183  return null;
184  }else{
185  $perm = Server::getInstance()->getPluginManager()->getPermission($name);
186  if($perm === null){
187  $perm = new Permission($name);
188  Server::getInstance()->getPluginManager()->addPermission($perm);
189  }
190 
191  $this->addParent($perm, $value);
192 
193  return $perm;
194  }
195  }

◆ getByName()

static getByName (   $value)
static
Parameters
$value
Returns
string
46  {
47  if(is_bool($value)){
48  if($value === true){
49  return "true";
50  }else{
51  return "false";
52  }
53  }
54  switch(strtolower($value)){
55  case "op":
56  case "isop":
57  case "operator":
58  case "isoperator":
59  case "admin":
60  case "isadmin":
61  return self::DEFAULT_OP;
62 
63  case "!op":
64  case "notop":
65  case "!operator":
66  case "notoperator":
67  case "!admin":
68  case "notadmin":
69  return self::DEFAULT_NOT_OP;
70 
71  case "true":
72  return self::DEFAULT_TRUE;
73 
74  default:
75  return self::DEFAULT_FALSE;
76  }
77  }

◆ getChildren()

& getChildren ( )
Returns
string[]
120  {
121  return $this->children;
122  }

◆ getDefault()

getDefault ( )
Returns
string
127  {
128  return $this->defaultValue;
129  }

◆ getDescription()

getDescription ( )
Returns
string
144  {
145  return $this->description;
146  }

◆ getName()

getName ( )
Returns
string
113  : string{
114  return $this->name;
115  }

◆ getPermissibles()

getPermissibles ( )
Returns
Permissible[]
158  {
159  return Server::getInstance()->getPluginManager()->getPermissionSubscriptions($this->name);
160  }

◆ loadPermission()

static loadPermission (   $name,
array  $data,
  $default = self::DEFAULT_OP,
$output = [] 
)
static
Parameters
string$name
array$data
string$default
array$output
Returns
Permission
Exceptions
222  {
223  $desc = null;
224  $children = [];
225  if(isset($data["default"])){
226  $value = Permission::getByName($data["default"]);
227  if($value !== null){
228  $default = $value;
229  }else{
230  throw new \InvalidStateException("'default' key contained unknown value");
231  }
232  }
233 
234  if(isset($data["children"])){
235  if(is_array($data["children"])){
236  foreach($data["children"] as $k => $v){
237  if(is_array($v)){
238  if(($perm = self::loadPermission($k, $v, $default, $output)) !== null){
239  $output[] = $perm;
240  }
241  }
242  $children[$k] = true;
243  }
244  }else{
245  throw new \InvalidStateException("'children' key is of wrong type");
246  }
247  }
248 
249  if(isset($data["description"])){
250  $desc = $data["description"];
251  }
252 
253  return new Permission($name, $desc, $default, $children);
254 
255  }

◆ loadPermissions()

static loadPermissions ( array  $data,
  $default = self::DEFAULT_OP 
)
static
Parameters
array$data
$default
Returns
Permission[]
203  {
204  $result = [];
205  foreach($data as $key => $entry){
206  $result[] = self::loadPermission($key, $entry, $default, $result);
207  }
208 
209  return $result;
210  }

◆ recalculatePermissibles()

recalculatePermissibles ( )
162  {
163  $perms = $this->getPermissibles();
164 
165  Server::getInstance()->getPluginManager()->recalculatePermissionDefaults($this);
166 
167  foreach($perms as $p){
168  $p->recalculatePermissions();
169  }
170  }

◆ setDefault()

setDefault (   $value)
Parameters
string$value
134  {
135  if($value !== $this->defaultValue){
136  $this->defaultValue = $value;
137  $this->recalculatePermissibles();
138  }
139  }

◆ setDescription()

setDescription (   $value)
Parameters
string$value
151  {
152  $this->description = $value;
153  }

Field Documentation

◆ $DEFAULT_PERMISSION

$DEFAULT_PERMISSION = self::DEFAULT_OP
static

◆ DEFAULT_FALSE

const DEFAULT_FALSE = "false"

◆ DEFAULT_NOT_OP

const DEFAULT_NOT_OP = "notop"

◆ DEFAULT_OP

const DEFAULT_OP = "op"

◆ DEFAULT_TRUE

const DEFAULT_TRUE = "true"

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