Search in sources :

Example 6 with Permission

use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.

the class DefaultPermissions method registerPermission.

public static Permission registerPermission(String name, String desc, PermissionDefault def, Map<String, Boolean> children, Permission parent) {
    Permission perm = registerPermission(name, desc, def, children);
    parent.getChildren().put(perm.getName(), true);
    return perm;
}
Also used : Permission(org.bukkit.permissions.Permission)

Example 7 with Permission

use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.

the class DefaultPermissions method registerPermission.

public static Permission registerPermission(Permission perm, boolean withLegacy) {
    Permission result = perm;
    try {
        Bukkit.getPluginManager().addPermission(perm);
    } catch (IllegalArgumentException ex) {
        result = Bukkit.getPluginManager().getPermission(perm.getName());
    }
    if (withLegacy) {
        Permission legacy = new Permission(LEGACY_PREFIX + result.getName(), result.getDescription(), PermissionDefault.FALSE);
        legacy.getChildren().put(result.getName(), true);
        registerPermission(perm, false);
    }
    return result;
}
Also used : Permission(org.bukkit.permissions.Permission)

Example 8 with Permission

use of org.bukkit.permissions.Permission in project Jobs by GamingMesh.

the class JobsListener method onWorldLoad.

@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoad(WorldLoadEvent event) {
    World world = event.getWorld();
    PluginManager pm = plugin.getServer().getPluginManager();
    if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
        pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Permission(org.bukkit.permissions.Permission) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Permission

use of org.bukkit.permissions.Permission in project Glowstone by GlowstoneMC.

the class GlowServer method enablePlugins.

/**
     * Enable all plugins of the given load order type.
     *
     * @param type The type of plugin to enable.
     */
private void enablePlugins(PluginLoadOrder type) {
    if (type == PluginLoadOrder.STARTUP) {
        helpMap.clear();
        helpMap.loadConfig(config.getConfigFile(Key.HELP_FILE));
    }
    // load all the plugins
    Plugin[] plugins = pluginManager.getPlugins();
    for (Plugin plugin : plugins) {
        if (!plugin.isEnabled() && plugin.getDescription().getLoad() == type) {
            List<Permission> perms = plugin.getDescription().getPermissions();
            for (Permission perm : perms) {
                try {
                    pluginManager.addPermission(perm);
                } catch (IllegalArgumentException ex) {
                    getLogger().log(Level.WARNING, "Plugin " + plugin.getDescription().getFullName() + " tried to register permission '" + perm.getName() + "' but it's already registered", ex);
                }
            }
            try {
                pluginManager.enablePlugin(plugin);
            } catch (Throwable ex) {
                logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
            }
        }
    }
    if (type == PluginLoadOrder.POSTWORLD) {
        commandMap.setFallbackCommands();
        commandMap.registerServerAliases();
        DefaultPermissions.registerCorePermissions();
        helpMap.initializeCommands();
        helpMap.amendTopics(config.getConfigFile(Key.HELP_FILE));
        // load permissions.yml
        ConfigurationSection permConfig = config.getConfigFile(Key.PERMISSIONS_FILE);
        Map<String, Map<String, Object>> data = new HashMap<>();
        permConfig.getValues(false).forEach((key, value) -> data.put(key, ((MemorySection) value).getValues(false)));
        List<Permission> perms = Permission.loadPermissions(data, "Permission node '%s' in permissions config is invalid", PermissionDefault.OP);
        for (Permission perm : perms) {
            try {
                pluginManager.addPermission(perm);
            } catch (IllegalArgumentException ex) {
                getLogger().log(Level.WARNING, "Permission config tried to register '" + perm.getName() + "' but it's already registered", ex);
            }
        }
    }
}
Also used : MemorySection(org.bukkit.configuration.MemorySection) Permission(org.bukkit.permissions.Permission) HelpMap(org.bukkit.help.HelpMap) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 10 with Permission

use of org.bukkit.permissions.Permission in project BKCommonLib by bergerhealer.

the class PluginBase method setPermissions.

private static void setPermissions(ConfigurationNode node) {
    for (ConfigurationNode subNode : node.getNodes()) {
        setPermissions(subNode);
    }
    PermissionDefault def = node.get("default", PermissionDefault.class);
    String desc = node.get("description", String.class);
    if (def != null || desc != null) {
        Permission permission = getPermission(node.getPath().toLowerCase());
        if (def != null) {
            permission.setDefault(def);
        }
        if (desc != null) {
            permission.setDescription(desc);
        }
    }
}
Also used : IPermissionDefault(com.bergerkiller.bukkit.common.permissions.IPermissionDefault) PermissionDefault(org.bukkit.permissions.PermissionDefault) ConfigurationNode(com.bergerkiller.bukkit.common.config.ConfigurationNode) Permission(org.bukkit.permissions.Permission)

Aggregations

Permission (org.bukkit.permissions.Permission)20 ConfigurationNode (com.bergerkiller.bukkit.common.config.ConfigurationNode)1 IPermissionDefault (com.bergerkiller.bukkit.common.permissions.IPermissionDefault)1 Job (com.gamingmesh.jobs.container.Job)1 JobPermission (com.gamingmesh.jobs.container.JobPermission)1 JobProgression (com.gamingmesh.jobs.container.JobProgression)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1 HashMap (java.util.HashMap)1 World (org.bukkit.World)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 MemorySection (org.bukkit.configuration.MemorySection)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 HelpMap (org.bukkit.help.HelpMap)1 PermissionAttachment (org.bukkit.permissions.PermissionAttachment)1 PermissionAttachmentInfo (org.bukkit.permissions.PermissionAttachmentInfo)1 PermissionDefault (org.bukkit.permissions.PermissionDefault)1 PluginManager (org.bukkit.plugin.PluginManager)1