[SOLVED] How to add permissions support to your plugin?

Discussion in 'Plugin Development' started by Tim Visee, Apr 10, 2011.

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

    Tim Visee

    Hello,

    I made my first (great) plugin, Fast Mining, and I want to add permissions support, how can I do that? I hope you know the answer!

    Thanks
    Tim Visée
     
  2. Offline

    Sammy

    Add this on your main file:
    Code:
        public PermissionHandler Permissions;
        private boolean UsePermissions;
    Code:
     public void onEnable() {
       setupPermissions();
    }
    Code:
        private void setupPermissions() {
            Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
    
            if (this.Permissions == null) {
                if (test != null) {
                    UsePermissions = true;
                    this.Permissions = ((Permissions) test).getHandler();
                    System.out.println("Permissions is enable for sdBountyHunter.");
                } else {
                    log.info("Permission system not detected, defaulting to OP");
                    UsePermissions = false;
                }
            }
        }
    
    For each command you want to implement add one of this on the main file too:
    Code:
        public boolean casUseCmdList(Player p) {
    
            if (UsePermissions) {
    
                return this.Permissions.has(p, "cmd.list");
    
            }
    
            return p.isOp();
    
        }
    on the command per-say add this if:
    Code:
     if (plugin.casCmdlist(ply)) {
    
       } else {
                    cs.sendMessage(ChatColor.RED + "You don't have permisson to use that command");
                }
     
  3. Offline

    Tim Visee

    WOW! Thanks, I'm going to try it right now!

    I think it works great, but what things must I import for 'Permissions' and 'PermissonsHandler'?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  4. Offline

    Sammy

    ohh, you need to add the permissions plugin to your library like you do with the bukkit.jar
     
  5. Offline

    Tim Visee

    I know, but what library?
    import org.bukkit.?????
     
  6. Offline

    Sammy

    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
     
    Tim Visee likes this.
  7. Offline

    Tim Visee

    Hmmm, i got a red line under 'com.nijiko' & 'com.nijikokun', what's the file to import to fix this, i hope that you know what i mean
     
  8. Offline

    Sammy

    I already told you Tim, you need to import the permissions.jar to your project, just like you do with the bukkit's jar :)
     
  9. Offline

    Tim Visee

    Oops, sorry. btw, THANKS! :)
     
  10. Offline

    Sammy

    No problem ;)
     
  11. Offline

    Tim Visee

    Solution (You can also find the solution here)
    Ok, How to add permission support to your project, (Summary of this threat)

    First of all, you must add the Permissions.jar plugin (for craftbukkit) to your project, just like you do the same as the bukkit's API jar.

    Go to your main file and add these two import things
    Code:
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    Add the following three things to your main file too
    Code:
    public PermissionHandler Permissions;
    private boolean UsePermissions;
    Code:
    public void onEnable() {
       setupPermissions();
    }
    Code:
    private void setupPermissions() {
        Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
        if (this.Permissions == null) {
            if (test != null) {
                UsePermissions = true;
                this.Permissions = ((Permissions) test).getHandler();
                System.out.println("Permissions is enable for sdBountyHunter.");
            } else {
                log.info("Permission system not detected, defaulting to OP");
                UsePermissions = false;
            }
        }
    }
    For each command you want to implement add one of this on the main file too
    Code:
    public boolean casUseCmdList(Player p) {
        if (UsePermissions) {
            return this.Permissions.has(p, "cmd.list");
        }
        return p.isOp();
    }
    On the command per-say add this if:
    Code:
    if (plugin.casCmdlist(ply)) {
    
    } else {
        cs.sendMessage(ChatColor.RED + "You don't have permisson to use that command");
    }
     
  12. Offline

    hellsome

    what is the command per-say?
     
Thread Status:
Not open for further replies.

Share This Page