public static loadPermissions ( array $data, $default = self::DEFAULT_OP ) : |
||
$data | array | |
$default | ||
Результат |
/** * @param array $plugin * * @throws PluginException */ private function loadMap(array $plugin) { $this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]); if ($this->name === "") { throw new PluginException("Invalid PluginDescription name"); } $this->name = str_replace(" ", "_", $this->name); $this->version = $plugin["version"]; $this->main = $plugin["main"]; $this->api = !is_array($plugin["api"]) ? [$plugin["api"]] : $plugin["api"]; if (stripos($this->main, "pocketmine\\") === 0) { throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace"); } if (isset($plugin["commands"]) and is_array($plugin["commands"])) { $this->commands = $plugin["commands"]; } if (isset($plugin["depend"])) { $this->depend = (array) $plugin["depend"]; } if (isset($plugin["softdepend"])) { $this->softDepend = (array) $plugin["softdepend"]; } if (isset($plugin["loadbefore"])) { $this->loadBefore = (array) $plugin["loadbefore"]; } if (isset($plugin["website"])) { $this->website = $plugin["website"]; } if (isset($plugin["description"])) { $this->description = $plugin["description"]; } if (isset($plugin["prefix"])) { $this->prefix = $plugin["prefix"]; } if (isset($plugin["load"])) { $order = strtoupper($plugin["load"]); if (!defined(PluginLoadOrder::class . "::" . $order)) { throw new PluginException("Invalid PluginDescription load"); } else { $this->order = constant(PluginLoadOrder::class . "::" . $order); } } $this->authors = []; if (isset($plugin["author"])) { $this->authors[] = $plugin["author"]; } if (isset($plugin["authors"])) { foreach ($plugin["authors"] as $author) { $this->authors[] = $author; } } if (isset($plugin["permissions"])) { $this->permissions = Permission::loadPermissions($plugin["permissions"]); } }
public function onEnable() { if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder(), 0777, true); } $buildInfo = json_decode($this->getResourceContents("meta.build.json")); $configFile = $this->getDataFolder() . "config.yml"; $os = Utils::getOS(); if ($os === "win") { $this->getServer()->getCommandMap()->register("wea", new StartConfigurationCommand($this)); } // register //wea-config if (is_file($configFile)) { $lines = file($configFile); if (trim($lines[0]) !== "---" or trim($lines[1]) !== "### WORLDEDITART GAMMA CONFIG FILE ###") { $this->getLogger()->warning("Using outdated config file! plugins/WorldEditArt/config.yml will be renamed into config.yml.old"); rename($configFile, $configFile . ".old"); } else { $ok = true; } } // warn old config if (!isset($ok)) { $this->getLogger()->notice("Thank you for using WorldEditArt Gamma!"); $this->getLogger()->notice("You are strongly encouraged to configure WorldEditArt using our installer."); if ($os === "win") { $this->getLogger()->notice("Type `/wea-config` then enter on console to start the installer."); } else { $this->getLogger()->notice("Please stop the server and run the SHELL COMMAND `" . PHP_BINARY . " " . Phar::running(false) . "` to start the installer."); } $this->getLogger()->notice("WorldEditArt will continue to run with the default configuration."); } // save default config $this->objectPool = new Fridge($this); if (true) { $langs = []; foreach (scandir($par = rtrim(Phar::running(), "/") . "/resources/lang/") as $file) { $path = $this->getDataFolder() . "lang/{$file}"; if (!is_dir($this->getDataFolder() . "lang")) { mkdir($this->getDataFolder() . "lang"); } if ($file !== "index.json" and strtolower(substr($path, -5)) === ".json") { $langs[substr($file, 0, -5)] = true; } if (!file_exists($path)) { file_put_contents($path, file_get_contents($par . $file)); } } $this->translationManager = new TranslationManager($this, $langs); } // initialize translations if (true) { $json = $this->getResourceContents("permissions.json"); $perms = json_decode($json, true); $stack = []; $this->walkPerms($stack, $perms); Permission::loadPermissions($perms); } // register permission nodes $this->sessionCollection = new SessionCollection($this); new WorldEditArtCommand($this); // TODO initialize data provider $em1 = TextFormat::GOLD; $em2 = TextFormat::LIGHT_PURPLE; $green = TextFormat::DARK_GREEN; $iso = $buildInfo->buildTime->ISO8601; $this->getLogger()->info("{$green} Enabled{$em1} WorldEditArt {$buildInfo->type} " . "#{$buildInfo->typeVersion}{$green} compiled on {$em2}" . str_replace("T", " ", $iso)); }