Solved Defining permission wildcards without plugin.yml

Discussion in 'Spigot Plugin Development' started by Islandscout, Jul 9, 2018.

  1. I'm currently working on a plugin and I've stumbled on how I should handle permissions. My plugin has a config containing a list of special items that a player can purchase given that they have the required permission to buy that item.

    Here's an example of permissions corresponding to a list of these special items:
    • market.buy.coolthing
    • market.buy.gizmo
    • market.buy.gadget
    • market.buy.cosmeticthingy
    How would I make a decent wildcard system so that market.buy.* grants the player permission to buy all items in a list? Is there already one that I can use?

    Defining wildcards in the plugin.yml is probably not an option, since the list is fully configurable.
     
  2. Aeternum

    Supporter

    You do not have to implement wildcards. For example lets say you have the following four permissions:
    plugin.is
    plugin.is.crazy
    plugin.is.really.crazy
    plugin.isnot.crazy

    When a player does an action that requires a permission be checked, it says okay, so player needs plugin.is.crazy in order to complete this action, it goes through the players perms and if it sees plugin.is.crazy then it grants it but if it finds plugin.is.*
    Then it says okay as long as the permission the player has to have matches everything up to the wildcard, then they have the permission.

    Not only do you not have to define wildcards, but there is not really a way TOO define wildcards in a plugin.
     
  3. That's the thing I'm having trouble with. The permissions should depend on whatever is put into the list in the configuration.

    If "coolthingy" is listed in the config, then market.buy.* should allow the user to buy a "coolthingy". I really don't feel like defining a permission for every possible name someone can come up with.
     
  4. Aeternum

    Supporter

    No, the permission plugin never touches your plugin.yml, well my new web dashboard on pex does, but thats to list perms of installed plugins.
    Permissions plugins go solely off the node you are checking and the node they have in the permission plugins config
    You cant and dont determine anything about wildcards.
    If i set a bunch of permissions in your plugin called things like
    cake.1
    cake.2
    cake.3

    And then i give my player cake.*
    The permissions plugin will verify that permission when they are checked for it.
     
  5. Checking permission through hasPermission or through vault for example automatically handles the wildcard for you, just use the permission nodes like normal.
     
  6. Aeternum

    Supporter

    All you are doing is saying
    if user has perm
    then do this

    spigot and bukkit hook into any installed permission managers, and pass that check onto the permission plugin. It handles it. You dont do anything.
     
  7. Aw man. I could've sworn that I had to go into plugin.yml and define something like some.permission.* and list a bunch of children.
     
    • Winner Winner x 1
  8. No...
     
  9. Aeternum

    Supporter

    And development requires tact, and no small amount of lazyness. You import a dictionary and a random generator, instead of writing every one of 10^99 combonations down :^)
     
  10. Aeternum

    Supporter

    Yes, if your plugin has a bunch of commands and arguments, you are supposed to list the commands and arguments, and if you have a bunch of permissions and child permissions, you are supposed to register them all in your plugin.yml. but not for the purpose of wildcards or anything to do with permissions checks, but for proper documentation, and I personally look up each plugins perms in their plugin.yml so that i can list them in the dashboard:
    [​IMG]
     
  11. I still don't get it. I just gave myself a permission like market.buy.* and apparently, hasPermission("market.buy.coolthing") returns false.

    I'm using... GroupManager. But it notifies me that I already have the permission market.buy.coolthing because I have market.buy.*. When I give myself market.buy.coolthing, the hasPermission method returns true.

    I haven't registered any permissions in my plugin.yml and I have no intentions to do so.
     
  12. Aeternum

    Supporter

    Well, stop using group manager, it has loads of its own issues. Use PermissionsEx or LuckPerms
    Especially luck perms if you need bungee, i dont support bungee anymore.
     
    • Winner Winner x 1
  13. Holy crap, it works!