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 = [];
88 private array $depend = [];
90 private array $softDepend = [];
92 private array $loadBefore = [];
93 private string $version;
98 private array $commands = [];
99 private string $description =
"";
101 private array $authors = [];
102 private string $website =
"";
103 private string $prefix =
"";
110 private array $permissions = [];
116 if(is_string($yamlString)){
117 $map = yaml_parse($yamlString);
127 $this->loadMap($map);
134 private function loadMap(array $plugin) : void{
135 $this->map = $plugin;
137 $this->name = $plugin[self::KEY_NAME];
138 if(preg_match(
'/^[A-Za-z0-9 _.-]+$/', $this->name) === 0){
141 $this->name = str_replace(
" ",
"_", $this->name);
142 $this->version = (string) $plugin[self::KEY_VERSION];
143 $this->main = $plugin[self::KEY_MAIN];
144 if(stripos($this->main,
"pocketmine\\") === 0){
145 throw new PluginDescriptionParseException(
"Invalid Plugin main, cannot start within the PocketMine namespace");
148 $this->srcNamespacePrefix = $plugin[self::KEY_SRC_NAMESPACE_PREFIX] ??
"";
150 $this->api = array_map(
"\strval", (array) ($plugin[self::KEY_API] ?? []));
151 $this->compatibleMcpeProtocols = array_map(
"\intval", (array) ($plugin[self::KEY_MCPE_PROTOCOL] ?? []));
152 $this->compatibleOperatingSystems = array_map(
"\strval", (array) ($plugin[self::KEY_OS] ?? []));
154 if(isset($plugin[self::KEY_COMMANDS]) && is_array($plugin[self::KEY_COMMANDS])){
155 foreach(Utils::promoteKeys($plugin[self::KEY_COMMANDS]) as $commandName => $commandData){
156 if(!is_string($commandName)){
157 throw new PluginDescriptionParseException(
"Invalid Plugin commands, key must be the name of the command");
159 if(!is_array($commandData)){
160 throw new PluginDescriptionParseException(
"Command $commandName has invalid properties");
162 if(!isset($commandData[self::KEY_COMMAND_PERMISSION]) || !is_string($commandData[self::KEY_COMMAND_PERMISSION])){
163 throw new PluginDescriptionParseException(
"Command $commandName does not have a valid permission set");
165 $this->commands[$commandName] =
new PluginDescriptionCommandEntry(
166 $commandData[self::KEY_COMMAND_DESCRIPTION] ??
null,
167 $commandData[self::KEY_COMMAND_USAGE] ??
null,
168 $commandData[self::KEY_COMMAND_ALIASES] ?? [],
169 $commandData[self::KEY_COMMAND_PERMISSION],
170 $commandData[self::KEY_COMMAND_PERMISSION_MESSAGE] ??
null
175 if(isset($plugin[self::KEY_DEPEND])){
176 $this->depend = (array) $plugin[self::KEY_DEPEND];
178 if(isset($plugin[self::KEY_EXTENSIONS])){
179 $extensions = (array) $plugin[self::KEY_EXTENSIONS];
180 $isLinear = $extensions === array_values($extensions);
181 foreach(Utils::promoteKeys($extensions) as $k => $v){
186 $this->extensions[(string) $k] = array_map(
'strval', is_array($v) ? $v : [$v]);
190 $this->softDepend = (array) ($plugin[self::KEY_SOFTDEPEND] ?? $this->softDepend);
192 $this->loadBefore = (array) ($plugin[self::KEY_LOADBEFORE] ?? $this->loadBefore);
194 $this->website = (string) ($plugin[self::KEY_WEBSITE] ?? $this->website);
196 $this->description = (string) ($plugin[self::KEY_DESCRIPTION] ?? $this->description);
198 $this->prefix = (string) ($plugin[self::KEY_LOGGER_PREFIX] ?? $this->prefix);
200 if(isset($plugin[self::KEY_LOAD])){
201 $order = PluginEnableOrder::fromString($plugin[self::KEY_LOAD]);
203 throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_LOAD .
"\"");
205 $this->order = $order;
207 $this->order = PluginEnableOrder::POSTWORLD;
211 if(isset($plugin[self::KEY_AUTHOR])){
212 if(is_array($plugin[self::KEY_AUTHOR])){
213 $this->authors = $plugin[self::KEY_AUTHOR];
215 $this->authors[] = $plugin[self::KEY_AUTHOR];
218 if(isset($plugin[self::KEY_AUTHORS])){
219 foreach($plugin[self::KEY_AUTHORS] as $author){
220 $this->authors[] = $author;
224 if(isset($plugin[self::KEY_PERMISSIONS])){
226 $this->permissions = PermissionParser::loadPermissions($plugin[self::KEY_PERMISSIONS]);
227 }
catch(PermissionParserException $e){
228 throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_PERMISSIONS .
"\": " . $e->getMessage(), 0, $e);
233 public function getFullName() : string{
234 return $this->name .
" v" . $this->version;
248 return $this->compatibleMcpeProtocols;
255 return $this->compatibleOperatingSystems;
262 return $this->authors;
265 public function getPrefix() : string{
266 return $this->prefix;
274 return $this->commands;
282 return $this->extensions;
289 return $this->depend;
292 public function getDescription() : string{
293 return $this->description;
300 return $this->loadBefore;
303 public function getMain() : string{
307 public function getSrcNamespacePrefix() : string{ return $this->srcNamespacePrefix; }
309 public function getName() : string{
322 return $this->permissions;
329 return $this->softDepend;
332 public function getVersion() : string{
333 return $this->version;
336 public function getWebsite() : string{
337 return $this->website;