PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
PluginDescription.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\plugin;
23 
26 
28  private $name;
29  private $main;
30  private $api;
31  private $depend = [];
32  private $softDepend = [];
33  private $loadBefore = [];
34  private $version;
35  private $commands = [];
36  private $description = null;
37  private $authors = [];
38  private $website = null;
39  private $prefix = null;
40  private $order = PluginLoadOrder::POSTWORLD;
41 
45  private $permissions = [];
46 
50  public function __construct($yamlString){
51  $this->loadMap(\yaml_parse($yamlString));
52  }
53 
59  private function loadMap(array $plugin){
60  $this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]);
61  if($this->name === ""){
62  throw new PluginException("Invalid PluginDescription name");
63  }
64  $this->name = str_replace(" ", "_", $this->name);
65  $this->version = $plugin["version"];
66  $this->main = $plugin["main"];
67  $this->api = !is_array($plugin["api"]) ? [$plugin["api"]] : $plugin["api"];
68  if(stripos($this->main, "pocketmine\\") === 0){
69  throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace");
70  }
71 
72  if(isset($plugin["commands"]) and is_array($plugin["commands"])){
73  $this->commands = $plugin["commands"];
74  }
75 
76  if(isset($plugin["depend"])){
77  $this->depend = (array) $plugin["depend"];
78  }
79  if(isset($plugin["softdepend"])){
80  $this->softDepend = (array) $plugin["softdepend"];
81  }
82  if(isset($plugin["loadbefore"])){
83  $this->loadBefore = (array) $plugin["loadbefore"];
84  }
85 
86  if(isset($plugin["website"])){
87  $this->website = $plugin["website"];
88  }
89  if(isset($plugin["description"])){
90  $this->description = $plugin["description"];
91  }
92  if(isset($plugin["prefix"])){
93  $this->prefix = $plugin["prefix"];
94  }
95  if(isset($plugin["load"])){
96  $order = strtoupper($plugin["load"]);
97  if(!defined(PluginLoadOrder::class . "::" . $order)){
98  throw new PluginException("Invalid PluginDescription load");
99  }else{
100  $this->order = constant(PluginLoadOrder::class . "::" . $order);
101  }
102  }
103  $this->authors = [];
104  if(isset($plugin["author"])){
105  $this->authors[] = $plugin["author"];
106  }
107  if(isset($plugin["authors"])){
108  foreach($plugin["authors"] as $author){
109  $this->authors[] = $author;
110  }
111  }
112 
113  if(isset($plugin["permissions"])){
114  $this->permissions = Permission::loadPermissions($plugin["permissions"]);
115  }
116  }
117 
121  public function getFullName(){
122  return $this->name . " v" . $this->version;
123  }
124 
128  public function getCompatibleApis(){
129  return $this->api;
130  }
131 
135  public function getAuthors(){
136  return $this->authors;
137  }
138 
142  public function getPrefix(){
143  return $this->prefix;
144  }
145 
149  public function getCommands(){
150  return $this->commands;
151  }
152 
156  public function getDepend(){
157  return $this->depend;
158  }
159 
163  public function getDescription(){
164  return $this->description;
165  }
166 
170  public function getLoadBefore(){
171  return $this->loadBefore;
172  }
173 
177  public function getMain(){
178  return $this->main;
179  }
180 
184  public function getName(){
185  return $this->name;
186  }
187 
191  public function getOrder(){
192  return $this->order;
193  }
194 
198  public function getPermissions(){
199  return $this->permissions;
200  }
201 
205  public function getSoftDepend(){
206  return $this->softDepend;
207  }
208 
212  public function getVersion(){
213  return $this->version;
214  }
215 
219  public function getWebsite(){
220  return $this->website;
221  }
222 }
static loadPermissions(array $data, $default=self::DEFAULT_OP)
Definition: Permission.php:201