/** * @param string $name * @param bool $default * @return Permission */ private function addChannelPermission($name, $default) { $name = $this->normalize($name); $perm = new Permission("chatchannels.channel.{$name}", "Allow joining channel '{$name}'", ($default === true or $default === Permission::DEFAULT_TRUE) ? Permission::DEFAULT_TRUE : Permission::DEFAULT_FALSE); $this->parentPerm->getChildren()[$perm->getName()] = $perm; $this->main->getServer()->getPluginManager()->getPermission($perm); return $perm; }
/** * @param Permission $perm * @param Permission $parent * * @return Permission */ public static function registerPermission(Permission $perm, Permission $parent = null) { if ($parent instanceof Permission) { $parent->getChildren()[$perm->getName()] = true; return self::registerPermission($perm); } Server::getInstance()->getPluginManager()->addPermission($perm); return Server::getInstance()->getPluginManager()->getPermission($perm->getName()); }
/** * @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"]); } }
/** * @param Permission $permission */ private function calculatePermissionDefault(Permission $permission) { Timings::$permissionDefaultTimer->startTiming(); if ($permission->getDefault() === Permission::DEFAULT_OP or $permission->getDefault() === Permission::DEFAULT_TRUE) { $this->defaultPermsOp[$permission->getName()] = $permission; $this->dirtyPermissibles(true); } if ($permission->getDefault() === Permission::DEFAULT_NOT_OP or $permission->getDefault() === Permission::DEFAULT_TRUE) { $this->defaultPerms[$permission->getName()] = $permission; $this->dirtyPermissibles(false); } Timings::$permissionDefaultTimer->startTiming(); }
/** * @param Permission|string $name * * @return bool */ public function isPermissionSet($name) { return isset($this->permissions[$name instanceof Permission ? $name->getName() : $name]); }
/** * @param string $name * @param array $data * @param string $default * @param array $output * * @return Permission * * @throws \Exception */ public static function loadPermission($name, array $data, $default = self::DEFAULT_OP, &$output = []) { $desc = null; $children = []; if (isset($data["default"])) { $value = Permission::getByName($data["default"]); if ($value !== null) { $default = $value; } else { throw new \InvalidStateException("'default' key contained unknown value"); } } if (isset($data["children"])) { if (is_array($data["children"])) { foreach ($data["children"] as $k => $v) { if (is_array($v)) { if (($perm = self::loadPermission($k, $v, $default, $output)) !== null) { $output[] = $perm; } } $children[$k] = true; } } else { throw new \InvalidStateException("'children' key is of wrong type"); } } if (isset($data["description"])) { $desc = $data["description"]; } return new Permission($name, $desc, $default, $children); }
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)); }