Solved Numeric value permissions

Discussion in 'Plugin Development' started by Ne0nx3r0, Mar 22, 2013.

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

    Ne0nx3r0

    What's the recommended way to handle giving users a permission that has a numeric value? e.g., how many times per day they can do X command, how many houses they can have, etc.?
     
  2. Offline

    Tirelessly

    Assuming your permission looks like "plugin.claimstuff.5"Loop through them, use .startsWith("plugin.claimstuff") and split on the "."
     
  3. Offline

    Ne0nx3r0

    I'd rather not do this as the number specified could be essentially unlimited, and I don't want to for example run 100 checks on every command.
     
  4. Offline

    Tirelessly

    You don't need to.
    Example:

    Player player has testplugin.heal.250 as a permission.

    Code:
    public int getAmtOfHeals(Player player){
        for(PermissionAttachmentInfo perm: player.getEffectivePermissions()){
            String permString = perm.getPermission();
            if(permString.startsWith("testplugin.heal.")){
               String[] amount = permString.split(".");
               Integer amountOfHeals = Integer.parseInt(amount[2]);
               return amountOfHeals;
            }
        }
    }
    
     
    Ne0nx3r0 and Codex Arcanum like this.
  5. Offline

    Ne0nx3r0

    Oh that's not so bad. I suppose looking up a permission directly basically runs a similar process anyway. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page