Solved The correct way to register permissions?

Discussion in 'Plugin Development' started by UNC00KED, Dec 23, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    UNC00KED

    What is the proper way to register permissions?

    I always get the error in the console:
    Code:
    Plugin PerWorldBroadcaster v1.0 tried to register permission 'PerWorldBroadcaster.use' but it's already registered

    The way I am currently doing it is:
    Code:
    public Permission playerPermission = new Permission("PerWorldBroadcaster.use");
    
    @Override
    public void onEnable() {
           
            plugin = this;
            new PerWorldBroadcasterListener(this);
            logger.info("PerWorldBroadcaster Enabled!");
            permissionAdd();
           
    }
    
    void permissionAdd() {
           
            PluginManager pm = getServer().getPluginManager();
            Set<Permission> permissions = pm.getPermissions();
           
            if (!permissions.contains(playerPermission)) {
               
                pm.addPermission(playerPermission);
               
            }
           
    }

    And yet I still get that error in console. Any ideas?
     
  2. Offline

    Mrs. bwfctower

    @UNC00KED You don't necessarily need to register any permissions. You can simply check if a CommandSender has it by using CommandSender#hasPermission(String perm) or CommandSender#hasPermission(Permissions perm).

    If you really want to register it, just put it in your plugin.yml under the 'permissions' section.
    http://wiki.bukkit.org/Plugin_YAML


    The reason the error is coming up is because you already have the permission in your plugin.yml, so when you try to register it again that error occurs.
     
    UNC00KED and Zombie_Striker like this.
  3. Offline

    UNC00KED

    Got it, thanks for the clarification! :)
     
Thread Status:
Not open for further replies.

Share This Page