Solved Breaking apart a permission node

Discussion in 'Plugin Development' started by NewDevOnTheBlock, May 5, 2015.

Thread Status:
Not open for further replies.
  1. For lack of a better phrase... I have what seems to be a rather complicated task that I cannot find a solution to.

    I need it so when a player have permission 'example.exam.hello' or 'example.exam.7' then I can check if they have permission node 'example.exam.X' (X being a String or int depending on what I need for a plugin).

    I've noticed the sole author @drtshock , who wrote the plugin PlayerVaults has done this with his permission node 'playervaults.amount.#' which will let you give a player however many vaults you want.

    It is also briefly mentioned, but not demonstrated in the Bukkit Plugin Tutorial just above the for-statement here.

    If anyone has a tutorial, previous work, example, tips on how to achieve this then that will be greatly appreciate to me and others trying to figure out this issue!

    Thank you
     
  2. Offline

    Konato_K

    @NewDevOnTheBlock

    player.hasPermission("my.fancy.permission." + i);

    Assuming i as anything that is needed?

    I don't really understand your question
     
  3. Offline

    stormneo7

    @NewDevOnTheBlock
    Code:
    int allowedAmount = 0;
    for(int i = 0; i  < {max}; i++){
      if(p.hasPermission("perm" + i)({
        allowedAmount = 0;
        break;
      }
    }
    Code:
    String examplePermission = "HomesPlugin.MaxHouses.50";
    String[] split = examplePermission.split("\\.");
    int maxAmount = Integer.parseInt(split[split.length - 1]);
     
  4. Offline

    Tecno_Wizard

    @stormneo7, spoon feeding won't get him anywhere, and that isn't what he asked for entirely.

    @NewDevOnTheBlock

    Player.getEffectivePermissions will get all of the perms.

    You then split the permission using the string.split method with a regular expression of a dot. (Splits the string by a dot) "//."

    Take the array and check if the first 2 equal the perm your looking for. If they do, check the last index and parse it into an integer. Make sure you don't accidently leave arrayindexoutofbounds errors And numberformatexceptions
     
    Last edited: May 5, 2015
  5. Offline

    stormneo7

    Never knew that. You've spoon fed me. Now feel guilty about it :mad:
     
  6. @stormneo7
    Thank you for the example. I believe I can handle the permission is it ends with an integer now. I need to start considering that I can allow the person using the plugin to have error on their end by putting the permission node twice... If you catch what I'm saying.

    @Tecno_Wizard Don't worry, he didn't do much to spoon feed me. I'm not completely dump in Java and understand everything he wrote. Your method should work to solve all ideas I have with this.

    Thank you guys!
     
  7. Offline

    Tecno_Wizard

Thread Status:
Not open for further replies.

Share This Page