Check for permissions e.t.c before cmd or what?

Discussion in 'Spigot Plugin Development' started by NaJated, May 8, 2015.

  1. hey all, should I do this:

    Code (Text):
            if (cmd.getName().equalsIgnoreCase("happyhour")) {
                if (sender.hasPermission("hi.there")) {
                    if (args.length == 0) {
    OR

    Code (Text):
            if (cmd.getName().equalsIgnoreCase("happyhour")) {
                                if (args.length == 0) {
                   if (sender.hasPermission("hi.there")) {
    {
    OR

    Code (Text):

                            if (sender.hasPermission("hi.there")) {
                        if (args[0].equalsIgnoreCase("start")) {

    and What do I do for else statements here?
    Code (Text):
                        if (args[0].equalsIgnoreCase("start") && sender.hasPermission("happyhour.start")) {
     
  2. First.
     
    • Like Like x 1
  3. I usually just check the permission right after the command. It make sense.
     
  4. Okay What about args tho?
     
  5. Uh well.. What do you mean?

    EDIT:

    This is usually how I check my permissions.

    PHP:
    if(cmd.getName().equalsIgnoreCase("access")) {
     
        if(!sender.hasPermission("access.use")) {
            sender.sendMessage("No permissions.");
        }else {
            //Do allowed functions.
            //Check arguments.
        }
    }
     
    • Like Like x 1
  6. checking for specifc arg permissions.
     
  7. Inkzzz

    Resource Staff

    Checking form permission(s), with commands and arguments really depends on how many commands you're having. I normally check the argument value, then permission.
     
    • Like Like x 1
  8. k bbe :D
     
  9. @IPv420 generally, do the fastest check first, unless you can't (ex. you generally want to group code for a single command together - even though you could just use a separate executor). Checking array length is faster than checking permissions, thus check array length first.
     
    • Like Like x 1
  10. Okay thanks :D