40 private const KEY_NAME =
"name";
41 private const KEY_VERSION =
"version";
42 private const KEY_MAIN =
"main";
43 private const KEY_SRC_NAMESPACE_PREFIX =
"src-namespace-prefix";
44 private const KEY_API =
"api";
45 private const KEY_MCPE_PROTOCOL =
"mcpe-protocol";
46 private const KEY_OS =
"os";
47 private const KEY_DEPEND =
"depend";
48 private const KEY_SOFTDEPEND =
"softdepend";
49 private const KEY_LOADBEFORE =
"loadbefore";
50 private const KEY_EXTENSIONS =
"extensions";
51 private const KEY_WEBSITE =
"website";
52 private const KEY_DESCRIPTION =
"description";
53 private const KEY_LOGGER_PREFIX =
"prefix";
54 private const KEY_LOAD =
"load";
55 private const KEY_AUTHOR =
"author";
56 private const KEY_AUTHORS =
"authors";
57 private const KEY_PERMISSIONS =
"permissions";
59 private const KEY_COMMANDS =
"commands";
60 private const KEY_COMMAND_PERMISSION =
"permission";
61 private const KEY_COMMAND_DESCRIPTION = self::KEY_DESCRIPTION;
62 private const KEY_COMMAND_USAGE =
"usage";
63 private const KEY_COMMAND_ALIASES =
"aliases";
64 private const KEY_COMMAND_PERMISSION_MESSAGE =
"permission-message";
74 private string $srcNamespacePrefix =
"";
78 private array $compatibleMcpeProtocols = [];
80 private array $compatibleOperatingSystems = [];
85 private array $extensions = [];
87 private array $depend = [];
89 private array $softDepend = [];
91 private array $loadBefore = [];
92 private string $version;
97 private array $commands = [];
98 private string $description =
"";
100 private array $authors = [];
101 private string $website =
"";
102 private string $prefix =
"";
103 private PluginEnableOrder $order;
109 private array $permissions = [];
115 if(is_string($yamlString)){
116 $map = yaml_parse($yamlString);
126 $this->loadMap($map);
133 private function loadMap(array $plugin) : void{
134 $this->map = $plugin;
136 $this->name = $plugin[self::KEY_NAME];
137 if(preg_match(
'/^[A-Za-z0-9 _.-]+$/', $this->name) === 0){
140 $this->name = str_replace(
" ",
"_", $this->name);
141 $this->version = (string) $plugin[self::KEY_VERSION];
142 $this->main = $plugin[self::KEY_MAIN];
143 if(stripos($this->main,
"pocketmine\\") === 0){
144 throw new PluginDescriptionParseException(
"Invalid Plugin main, cannot start within the PocketMine namespace");
147 $this->srcNamespacePrefix = $plugin[self::KEY_SRC_NAMESPACE_PREFIX] ??
"";
149 $this->api = array_map(
"\strval", (array) ($plugin[self::KEY_API] ?? []));
150 $this->compatibleMcpeProtocols = array_map(
"\intval", (array) ($plugin[self::KEY_MCPE_PROTOCOL] ?? []));
151 $this->compatibleOperatingSystems = array_map(
"\strval", (array) ($plugin[self::KEY_OS] ?? []));
153 if(isset($plugin[self::KEY_COMMANDS]) && is_array($plugin[self::KEY_COMMANDS])){
154 foreach($plugin[self::KEY_COMMANDS] as $commandName => $commandData){
155 if(!is_string($commandName)){
156 throw new PluginDescriptionParseException(
"Invalid Plugin commands, key must be the name of the command");
158 if(!is_array($commandData)){
159 throw new PluginDescriptionParseException(
"Command $commandName has invalid properties");
161 if(!isset($commandData[self::KEY_COMMAND_PERMISSION]) || !is_string($commandData[self::KEY_COMMAND_PERMISSION])){
162 throw new PluginDescriptionParseException(
"Command $commandName does not have a valid permission set");
164 $this->commands[$commandName] =
new PluginDescriptionCommandEntry(
165 $commandData[self::KEY_COMMAND_DESCRIPTION] ??
null,
166 $commandData[self::KEY_COMMAND_USAGE] ??
null,
167 $commandData[self::KEY_COMMAND_ALIASES] ?? [],
168 $commandData[self::KEY_COMMAND_PERMISSION],
169 $commandData[self::KEY_COMMAND_PERMISSION_MESSAGE] ??
null
174 if(isset($plugin[self::KEY_DEPEND])){
175 $this->depend = (array) $plugin[self::KEY_DEPEND];
177 if(isset($plugin[self::KEY_EXTENSIONS])){
178 $extensions = (array) $plugin[self::KEY_EXTENSIONS];
179 $isLinear = $extensions === array_values($extensions);
180 foreach($extensions as $k => $v){
185 $this->extensions[(string) $k] = array_map(
'strval', is_array($v) ? $v : [$v]);
189 $this->softDepend = (array) ($plugin[self::KEY_SOFTDEPEND] ?? $this->softDepend);
191 $this->loadBefore = (array) ($plugin[self::KEY_LOADBEFORE] ?? $this->loadBefore);
193 $this->website = (string) ($plugin[self::KEY_WEBSITE] ?? $this->website);
195 $this->description = (string) ($plugin[self::KEY_DESCRIPTION] ?? $this->description);
197 $this->prefix = (string) ($plugin[self::KEY_LOGGER_PREFIX] ?? $this->prefix);
199 if(isset($plugin[self::KEY_LOAD])){
200 $order = PluginEnableOrder::fromString($plugin[self::KEY_LOAD]);
202 throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_LOAD .
"\"");
204 $this->order = $order;
206 $this->order = PluginEnableOrder::POSTWORLD;
210 if(isset($plugin[self::KEY_AUTHOR])){
211 if(is_array($plugin[self::KEY_AUTHOR])){
212 $this->authors = $plugin[self::KEY_AUTHOR];
214 $this->authors[] = $plugin[self::KEY_AUTHOR];
217 if(isset($plugin[self::KEY_AUTHORS])){
218 foreach($plugin[self::KEY_AUTHORS] as $author){
219 $this->authors[] = $author;
223 if(isset($plugin[self::KEY_PERMISSIONS])){
225 $this->permissions = PermissionParser::loadPermissions($plugin[self::KEY_PERMISSIONS]);
226 }
catch(PermissionParserException $e){
227 throw new PluginDescriptionParseException(
"Invalid Plugin \"" . self::KEY_PERMISSIONS .
"\": " . $e->getMessage(), 0, $e);
232 public function getFullName() : string{
233 return $this->name .
" v" . $this->version;
247 return $this->compatibleMcpeProtocols;
254 return $this->compatibleOperatingSystems;
261 return $this->authors;
264 public function getPrefix() : string{
265 return $this->prefix;
273 return $this->commands;
281 return $this->extensions;
288 return $this->depend;
291 public function getDescription() : string{
292 return $this->description;
299 return $this->loadBefore;
302 public function getMain() : string{
306 public function getSrcNamespacePrefix() : string{ return $this->srcNamespacePrefix; }
308 public function getName() : string{
312 public function getOrder() : PluginEnableOrder{
321 return $this->permissions;
328 return $this->softDepend;
331 public function getVersion() : string{
332 return $this->version;
335 public function getWebsite() : string{
336 return $this->website;