Problem with permissions.

Discussion in 'Plugin Development' started by Schwarzer Zylinder, Nov 19, 2011.

Thread Status:
Not open for further replies.
  1. Hey, I got some problem with permissions on my plugin DynamicShop.
    It is a shop plugin, you can buy or sell by commands or signs.
    This two permissions doesn't work properly:
    dynshop.buy.<trader>.<material>: true
    dynshop.sell.<trader>.<material>: true
    Trader: 'cmd' or 'sign', with sign permission you can buy via signs, with cmd via commands

    As you can see, you have permissions for every material. I don't want to register for every material an own permission, is there any other way?

    Plugin.yml:
    Code:
    name: Dynamic Shop
    main: me.gerry.dynamicshop.DynamicShop
    author: Schwarzer Zylinder
    version: 1.3
    commands:
        dynshop:
            buy:
                description: Use this to buy items.
                usage: /dynshop buy (material) [amount]
            sell:
                description: Use this to sell items.
                usage: /dynshop sell (material) [amount]
            price:
                description: Returns the price for the material.
                usage: /dynshop price (material)
            setprice:
                description: Changes the price.
                usage: /dynshop setprice (material) (amount)
            setpricechange:
                description: Changes the pricechange.
                usage: /dynshop setpricechange (percent, amount or constant)
            setpricechangespeed:
                description: Changes the pricechangespeed.
                usage: /dynshop setpricechange (speed)
            usage: |
               Usage: /dynshop (command)
               buy (material) [amount]
               sell (material) [amount]
               price (material) - Gets the actual price for the item.
               selltax - Gets the actual sell tax.
               setprice (material) (amount)
               setpricechange (percent, amount or constant)
               setpricechangespeed (speed)
               setselltax (tax)
    permissions:
        dynshop.*:
            description: Gives access to all DynamicShop commands.
            children:
                dynshop.buy: true
                dynshop.sell: true
                dynshop.price: true
                dynshop.selltax: true
                dynshop.setprice: false
                dynshop.setpricechange: false
                dynshop.setpricechangespeed: false
                dynshop.setselltax: false
                dynshop.signcreate: false
                dynshop.psigncreate: true
        dynshop.buy.*:
            description: Allows you to buy items.
            children:
                dynshop.buy.cmd: true
                dynshop.buy.sign: true
        dynshop.sell:
            description: Allows you to sell items.
            children:
                dynshop.sell.cmd: true
                dynshop.sell.sign: true
        dynshop.price:
            description: Allows you to get actual item prices.
        dynshop.selltax:
            description: Allows you to get actual sell taxes.
        dynshop.setprice:
            description: Allows you to set the price.
        dynshop.setpricechange:
            description: Allows you to set the pricechange.
        dynshop.setpricechangespeed:
            description: Allows you to set the pricechangespeed.
        dynshop.setselltax:
            description: Allows you to set the sell tax.
        dynshop.signcreate:
            description: Allows you to create shop sign
        dynshop.psigncreate:
            description: Allows you to create pshop sign
     
  2. Offline

    Evenprime

    First, you are inconsistent with naming your permission nodes. You have defined "dynshop.*", which has a child "dynshop.buy" and "dynshop.sell". But only "dynshop.sell" is defined, "dynshop.buy" is not (you defined "dynshop.buy.*", which is not the same). In general I'd recommend to not use the "*" at all in permission names. Plugins tend to give it different meanings (so you should drop the ".*" of "dynshop.*" permission node definition too).

    To solve your problem on how to define the various subpermissions for traders and materials in plugin.yml. Don't. Rather do the check in your code:

    Code:
    public boolean canBuyMaterialFromTrader(Player player, String trader, String material) {
    
      if(player.isPermissionSet("dynshop.buy."+trader+"."+material))
        return player.hasPermission("dynshop.buy."+trader+"."+material);
      else if(player.isPermissionSet("dynshop.buy."+trader))
        return player.hasPermission("dynshop.buy."+trader);
      else {
        return player.hasPermission("dynshop.buy");
    }
    
    That should work for all SuperPerms permissions plugins and also respect node negation (e.g. a player has "dynshop.buy" and "-dynshop.buy.tooltrader", so he can't buy at "tooltrader"s shop, but everywhere else). No "*" involved at all, therefore it should work for all SuperPerms permissions plugins. Players have to define all their permissions for your plugin without the ".*" at the end.

    Again: I didn't fully test it, but from my experience I'd say it should work and do exactly what you want.

    PS: And it is uses way less resources compared to creating permission nodes for every single "trader" + "material" combination.

    EDIT: The only limitation of that approach is that other plugins may have problems reading the permissions of your plugin, as they'd hav to use the above construct too to really get the correct results. But I guess your plugin is the only plugin that uses these nodes, so you should be fine.

    Ok, just tested it. It works with all plugins, except for PermissionsEx. PermissionsEx returns to the question "isPermissionSet( ... )" false all the time.

    That's a pretty big bug in PermissionsEx and I'll open a support ticket for that now.

    I've opened a ticket for the problem with PermissionsEx: https://github.com/t3hk0d3/PermissionsEx/issues/132

    I'm not sure how you could code around that limitation of PermissionsEx, as there is no way to differenciate between something not being set at all or something intentionally being set to false in PermissionsEx.

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

    t3hk0d3

    Fixed :D
     
  4. I added permissions ingame and it works fine.
    I want to have only one method to check all permissions, so your solution wouldn't fit.

    But thanks anyway =)
     
Thread Status:
Not open for further replies.

Share This Page