Package org.bukkit.permissions

Examples of org.bukkit.permissions.Permission


       
        boolean changed = false;
       
        // remove old permissions
        String permName = "jobs.players."+player.getName();
        Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
        if (permission != null) {
            plugin.getServer().getPluginManager().removePermission(permission);
            changed = true;
        }
       
        // Permissions should only apply if we have permission to use jobs in this world
        if (hasWorldPermission(player, player.getWorld().getName())) {
            List<JobProgression> progression = jPlayer.getJobProgression();
            // calculate new permissions
            HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
            if (progression.size() == 0) {
                Job job = Jobs.getNoneJob();
                if (job != null) {
                    for (JobPermission perm : job.getPermissions()) {
                        if (perm.getLevelRequirement() <= 0) {
                            if (perm.getValue()) {
                                permissions.put(perm.getNode(), true);
                            } else {
                                /*
                                 * If the key exists, don't put a false node in
                                 * This is in case we already have a true node there
                                 */
                                if (!permissions.containsKey(perm.getNode())) {
                                    permissions.put(perm.getNode(), false);
                                }
                            }
                        }
                    }
                }
            } else {
                for (JobProgression prog : progression) {
                    for (JobPermission perm : prog.getJob().getPermissions()) {
                        if (prog.getLevel() >= perm.getLevelRequirement()) {
                            /*
                             * If the key exists, don't put a false node in
                             * This is in case we already have a true node there
                             */
                            if (perm.getValue()) {
                                permissions.put(perm.getNode(), true);
                            } else {
                                if (!permissions.containsKey(perm.getNode())) {
                                    permissions.put(perm.getNode(), false);
                                }
                            }
                        }
                    }
                }
            }
           
            // add new permissions (if applicable)
            if (permissions.size() > 0) {
                plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
                changed = true;
            }
        }
       
        // If the permissions changed, recalculate them
View Full Code Here


   
    public void registerPermissions() {
        PluginManager pm = plugin.getServer().getPluginManager();
        for (World world : plugin.getServer().getWorlds()) {
            if (pm.getPermission("jobs.world."+world.getName().toLowerCase()) == null)
                pm.addPermission(new Permission("jobs.world."+world.getName().toLowerCase(), PermissionDefault.TRUE));
        }
        for (Job job : Jobs.getJobs()) {
            if (pm.getPermission("jobs.join."+job.getName().toLowerCase()) == null)
                pm.addPermission(new Permission("jobs.join."+job.getName().toLowerCase(), PermissionDefault.TRUE));
        }
    }
View Full Code Here

    @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));
    }
View Full Code Here

        } else if (subcommand.equals("info")) {
            if (!checkPerm(sender, "info")) return true;
            if (split.length != 2) return usage(sender, command, subcommand);
           
            String node = split[1];
            Permission perm = plugin.getServer().getPluginManager().getPermission(node);
           
            if (perm == null) {
                sender.sendMessage(ChatColor.RED + "Permission " + ChatColor.WHITE + node + ChatColor.RED + " not found.");
            } else {
                sender.sendMessage(ChatColor.GREEN + "Info on permission " + ChatColor.WHITE + perm.getName() + ChatColor.GREEN + ":");
                sender.sendMessage(ChatColor.GREEN + "Default: " + ChatColor.WHITE + perm.getDefault());
                if (perm.getDescription() != null && perm.getDescription().length() > 0) {
                    sender.sendMessage(ChatColor.GREEN + "Description: " + ChatColor.WHITE + perm.getDescription());
                }
                if (perm.getChildren() != null && perm.getChildren().size() > 0) {
                    sender.sendMessage(ChatColor.GREEN + "Children: " + ChatColor.WHITE + perm.getChildren().size());
                }
            }
            return true;
        } else if (subcommand.equals("dump")) {
            if (!checkPerm(sender, "dump")) return true;
View Full Code Here

  }

  private void registerPermissions() {

    getServer().getPluginManager().addPermission(
        new Permission("bPermissions.admin", PermissionDefault.OP));
    getServer().getPluginManager().addPermission(
        new Permission("bPermissions.build", PermissionDefault.OP));

  }
View Full Code Here

            addDynamicPermission("mcmmo.commands.ptp.world." + world.getName(), PermissionDefault.OP, pluginManager);
        }
    }

    private static void addDynamicPermission(String permissionName, PermissionDefault permissionDefault, PluginManager pluginManager) {
        Permission permission = new Permission(permissionName);
        permission.setDefault(permissionDefault);
        pluginManager.addPermission(permission);
    }
View Full Code Here

    public void testRemovePermissionByPermissionCamel() {
        this.testRemovePermissionByPermission("CaMeL");
    }

    private void testRemovePermissionByName(final String name) {
        final Permission perm = new Permission(name);
        pm.addPermission(perm);
        assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm));
        pm.removePermission(name);
        assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue()));
    }
View Full Code Here

        pm.removePermission(name);
        assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue()));
    }

    private void testRemovePermissionByPermission(final String name) {
        final Permission perm = new Permission(name);
        pm.addPermission(perm);
        assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm));
        pm.removePermission(perm);
        assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue()));
    }
View Full Code Here

    public static Permission registerPermission(Permission perm) {
        return registerPermission(perm, true);
    }

    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;
    }
View Full Code Here

        parent.getChildren().put(perm.getName(), true);
        return registerPermission(perm);
    }

    public static Permission registerPermission(String name, String desc) {
        Permission perm = registerPermission(new Permission(name, desc));
        return perm;
    }
View Full Code Here

TOP

Related Classes of org.bukkit.permissions.Permission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.