mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
PermissionParser: add emitPermissions()
This commit is contained in:
parent
efc2d72d5f
commit
7aa263d320
@ -124,4 +124,39 @@ class PermissionParser{
|
||||
|
||||
return new Permission($name, $desc, $default, $children);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission[] $permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function emitPermissions(array $permissions) : array{
|
||||
$result = [];
|
||||
foreach($permissions as $permission){
|
||||
$result[$permission->getName()] = self::emitPermission($permission);
|
||||
}
|
||||
ksort($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function emitPermission(Permission $permission) : array{
|
||||
$result = [
|
||||
"description" => $permission->getDescription(),
|
||||
"default" => $permission->getDefault()
|
||||
];
|
||||
$children = [];
|
||||
foreach($permission->getChildren() as $name => $bool){
|
||||
//TODO: really? wtf??? this system is so overengineered it makes my head hurt...
|
||||
$child = PermissionManager::getInstance()->getPermission($name);
|
||||
if($child === null){
|
||||
throw new \UnexpectedValueException("Permission child should be a registered permission");
|
||||
}
|
||||
$children[$name] = self::emitPermission($child);
|
||||
}
|
||||
if(!empty($children)){
|
||||
ksort($children);
|
||||
$result["children"] = $children;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user