41    private const KEY_NAME = 
"name";
 
   42    private const KEY_VERSION = 
"version";
 
   43    private const KEY_MAIN = 
"main";
 
   44    private const KEY_SRC_NAMESPACE_PREFIX = 
"src-namespace-prefix";
 
   45    private const KEY_API = 
"api";
 
   46    private const KEY_MCPE_PROTOCOL = 
"mcpe-protocol";
 
   47    private const KEY_OS = 
"os";
 
   48    private const KEY_DEPEND = 
"depend";
 
   49    private const KEY_SOFTDEPEND = 
"softdepend";
 
   50    private const KEY_LOADBEFORE = 
"loadbefore";
 
   51    private const KEY_EXTENSIONS = 
"extensions";
 
   52    private const KEY_WEBSITE = 
"website";
 
   53    private const KEY_DESCRIPTION = 
"description";
 
   54    private const KEY_LOGGER_PREFIX = 
"prefix";
 
   55    private const KEY_LOAD = 
"load";
 
   56    private const KEY_AUTHOR = 
"author";
 
   57    private const KEY_AUTHORS = 
"authors";
 
   58    private const KEY_PERMISSIONS = 
"permissions";
 
   60    private const KEY_COMMANDS = 
"commands";
 
   61    private const KEY_COMMAND_PERMISSION = 
"permission";
 
   62    private const KEY_COMMAND_DESCRIPTION = self::KEY_DESCRIPTION;
 
   63    private const KEY_COMMAND_USAGE = 
"usage";
 
   64    private const KEY_COMMAND_ALIASES = 
"aliases";
 
   65    private const KEY_COMMAND_PERMISSION_MESSAGE = 
"permission-message";
 
   75    private string $srcNamespacePrefix = 
"";
 
   79    private array $compatibleMcpeProtocols = [];
 
   81    private array $compatibleOperatingSystems = [];
 
   86    private array $extensions = [];
 
   91    private array $depend = [];
 
   96    private array $softDepend = [];
 
  101    private array $loadBefore = [];
 
  102    private string $version;
 
  107    private array $commands = [];
 
  108    private string $description = 
"";
 
  110    private array $authors = [];
 
  111    private string $website = 
"";
 
  112    private string $prefix = 
"";
 
  119    private array $permissions = [];
 
  125        if(is_string($yamlString)){
 
  126            $map = yaml_parse($yamlString);
 
  136        $this->loadMap($map);
 
 
  143    private function loadMap(array $plugin) : void{
 
  144        $this->map = $plugin;
 
  146        $this->name = $plugin[self::KEY_NAME];
 
  147        if(preg_match(
'/^[A-Za-z0-9 _.-]+$/', $this->name) === 0){
 
  150        $this->name = str_replace(
" ", 
"_", $this->name);
 
  151        $this->version = (string) $plugin[self::KEY_VERSION];
 
  152        $this->main = $plugin[self::KEY_MAIN];
 
  153        if(stripos($this->main, 
"pocketmine\\") === 0){
 
  154            throw new PluginDescriptionParseException(
"Invalid Plugin main, cannot start within the PocketMine namespace");
 
  157        $this->srcNamespacePrefix = $plugin[self::KEY_SRC_NAMESPACE_PREFIX] ?? 
"";
 
  159        $this->api = array_map(
"\strval", (array) ($plugin[self::KEY_API] ?? []));
 
  160        $this->compatibleMcpeProtocols = array_map(
"\intval", (array) ($plugin[self::KEY_MCPE_PROTOCOL] ?? []));
 
  161        $this->compatibleOperatingSystems = array_map(
"\strval", (array) ($plugin[self::KEY_OS] ?? []));
 
  163        if(isset($plugin[self::KEY_COMMANDS]) && is_array($plugin[self::KEY_COMMANDS])){
 
  164            foreach(Utils::promoteKeys($plugin[self::KEY_COMMANDS]) as $commandName => $commandData){
 
  165                if(!is_string($commandName)){
 
  166                    throw new PluginDescriptionParseException(
"Invalid Plugin commands, key must be the name of the command");
 
  168                if(!is_array($commandData)){
 
  169                    throw new PluginDescriptionParseException(
"Command $commandName has invalid properties");
 
  171                if(!isset($commandData[self::KEY_COMMAND_PERMISSION]) || !is_string($commandData[self::KEY_COMMAND_PERMISSION])){
 
  172                    throw new PluginDescriptionParseException(
"Command $commandName does not have a valid permission set");
 
  174                $this->commands[$commandName] = 
new PluginDescriptionCommandEntry(
 
  175                    $commandData[self::KEY_COMMAND_DESCRIPTION] ?? 
null,
 
  176                    $commandData[self::KEY_COMMAND_USAGE] ?? 
null,
 
  177                    $commandData[self::KEY_COMMAND_ALIASES] ?? [],
 
  178                    $commandData[self::KEY_COMMAND_PERMISSION],
 
  179                    $commandData[self::KEY_COMMAND_PERMISSION_MESSAGE] ?? 
null 
  184        if(isset($plugin[self::KEY_DEPEND])){
 
  185            $this->depend = array_values((array) $plugin[self::KEY_DEPEND]);
 
  187        if(isset($plugin[self::KEY_EXTENSIONS])){
 
  188            $extensions = (array) $plugin[self::KEY_EXTENSIONS];
 
  189            $isLinear = $extensions === array_values($extensions);
 
  190            foreach(Utils::promoteKeys($extensions) as $k => $v){
 
  195                $this->extensions[(string) $k] = array_values(array_map(
'strval', is_array($v) ? $v : [$v]));
 
  199        $this->softDepend = array_values((array) ($plugin[self::KEY_SOFTDEPEND] ?? $this->softDepend));
 
  201        $this->loadBefore = array_values((array) ($plugin[self::KEY_LOADBEFORE] ?? $this->loadBefore));
 
  203        $this->website = (string) ($plugin[self::KEY_WEBSITE] ?? $this->website);
 
  205        $this->description = (string) ($plugin[self::KEY_DESCRIPTION] ?? $this->description);
 
  207        $this->prefix = (string) ($plugin[self::KEY_LOGGER_PREFIX] ?? $this->prefix);
 
  209        if(isset($plugin[self::KEY_LOAD])){
 
  210            $order = PluginEnableOrder::fromString($plugin[self::KEY_LOAD]);
 
  212                throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_LOAD . 
"\"");
 
  214            $this->order = $order;
 
  216            $this->order = PluginEnableOrder::POSTWORLD;
 
  220        if(isset($plugin[self::KEY_AUTHOR])){
 
  221            if(is_array($plugin[self::KEY_AUTHOR])){
 
  222                $this->authors = array_values($plugin[self::KEY_AUTHOR]);
 
  224                $this->authors[] = $plugin[self::KEY_AUTHOR];
 
  227        if(isset($plugin[self::KEY_AUTHORS])){
 
  228            foreach($plugin[self::KEY_AUTHORS] as $author){
 
  229                $this->authors[] = $author;
 
  233        if(isset($plugin[self::KEY_PERMISSIONS])){
 
  235                $this->permissions = PermissionParser::loadPermissions($plugin[self::KEY_PERMISSIONS]);
 
  236            }
catch(PermissionParserException $e){
 
  237                throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_PERMISSIONS . 
"\": " . $e->getMessage(), 0, $e);
 
  242    public function getFullName() : string{
 
  243        return $this->name . 
" v" . $this->version;
 
  257        return $this->compatibleMcpeProtocols;
 
 
  264        return $this->compatibleOperatingSystems;
 
 
  271        return $this->authors;
 
 
  274    public function getPrefix() : string{
 
  275        return $this->prefix;
 
  283        return $this->commands;
 
 
  291        return $this->extensions;
 
 
  299        return $this->depend;
 
 
  302    public function getDescription() : string{
 
  303        return $this->description;
 
  311        return $this->loadBefore;
 
 
  314    public function getMain() : string{
 
  318    public function getSrcNamespacePrefix() : string{ return $this->srcNamespacePrefix; }
 
  320    public function getName() : string{
 
  333        return $this->permissions;
 
 
  341        return $this->softDepend;
 
 
  344    public function getVersion() : string{
 
  345        return $this->version;
 
  348    public function getWebsite() : string{
 
  349        return $this->website;