Help With Checking Permissions

Discussion in 'Spigot Plugin Development' started by MrEminent42, May 28, 2015.

  1. So I'm making a plugin that locks down a server at a level, and anyone who has a the permission "lockdown.bypass.#" with the # being larger than the lockdown level can join the server. The only problem, I'm stuck with:
    if (p.hasPermission("lockdown.bypass." + String.valueOf(i)));
    And I can't use a for loop to get the highest level permission the player has because I don't want the level to have a limit (the for loop would be like i < infinity xD)

    Any suggestions?

    EDIT: To make it more clear, if the lockdown is level 5, and someone has permission "lockdown.bypass.6" or "lockdown.bypass.102350" etc. they can join.
     
    #1 MrEminent42, May 28, 2015
    Last edited: May 28, 2015
  2. Inkzzz

    Resource Staff

    Check the lock down level of the server so...
    if(p.hasPermisson("perm" + getLockdownLevel());
     
  3. I want him to be able to join if he has that permission or higher.

    So if the lockdown is level 5, and someone has permission "lockdown.bypass.6" or "lockdown.bypass.100000" etc. they can join.
     
  4. Register the permission on the plugin.yml
     
  5. No thats not my problem. I want him to be able to join if he has lockdown.bypass.<locked-level> permission or a higher number.
     
  6. Since you have String.valueOf(i) that means you have the lockdown figure. You can separate the player's permission with String.split("."); and parse the last figure for an integer, then check if permission is greater than i.
     
  7. Thanks! Thats exactly what I was looking for! Ill add that now :)

    P.S. its not String.valueOf(i); isnt static :p
     
  8. Inkzzz

    Resource Staff

    Code (Text):
    public boolean allow(Player p, int lockdownlevel) {
            String perm = "perm.lockdown.<number>";
            perm.replace("perm.lockdown.", "");
            int number = Integer.parseInt(perm);
            for (int i = lockdownlevel; i < number; i++) {
                // code
                return true;
            }
            return false;
        }
    This may work, I'm not entirely sure what you mean though.
     
  9. One thing I realized, how would I get the permission string? Like the one I would split? I can't use p.hasPermission() because that finds a permission that equals that, not contains that.
     
  10. Thanks but thats not exactly what I mean. Here is I think a better explanation.

    Server is locked down at level 5.
    Player with lockdown.bypass.2 tries to join > he is kicked because the lockdown level is higher than his permission.
    Player with lockdown.bypass.5 tries to join > he is allowed to join because that number is greater than or equal to the lockdown level.
    Player with lockdown.bypass.35 tries to join > he is allowed to join because that number is greater than or equal to the lockdown level.
     
  11. May not be the most efficient way:
    Code (Text):
    for(PermissionAttachmentInfo pao : player.getEffectivePermissions()) {
        //check if pao.getPermission() contains what you are looking for either with contains() or regex for integer value
    }
     
  12. Thanks! I'll give this a try.