Can someone explain permissions and how to set them?

Discussion in 'Plugin Development' started by kag359six, Jun 29, 2012.

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

    kag359six

    I have looked at several forums but none have explained how to set up permissions. The doorman example didnt really explain anything to me. Can somebody actually explain how to use permissions in Bukkit? If i need to use permissionBukkit, then how do i use that with my plugin? Neither seem to be well documented.
     
  2. Offline

    bartboy8

  3. Offline

    EnvisionRed

    You don't need a permissions plugin.
    In the plugin.yml there is a permissions section like so:
    Code:
    permissions:
      somepermission:
        description: lets a player do something or other
        default: op
      otherpermission:
        description: lets a player do something else
        default: op
    Then in your plugin, you might want to test if a player has a permission before doing so.
    Code:
    if (player.hasPermission("somepermission"){
    //do something
    }
    That's what OP was talking about with the doorman thing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
    grummbunger and Pingre like this.
  4. Offline

    kag359six

  5. Offline

    EnvisionRed

    It actually explains perfectly, I suggest you give it another read if you don't understand.
     
  6. Offline

    kag359six

    so do i name the permission whatever i want? How does it know what permissions is related to what command?

    so is the doorman the class containing the commands?

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

    EnvisionRed

    Okay, it seems you barely gave the tutorial a glance, so I will try to help you here.
    In the plugin.yml, define the permissions. Call them whatever the hell you want (typically something like yourpluginsname.somenode, e.g. SmartExp.check)

    Now, when a command is issued, let's call it test, you check if the player has the permission.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if (cmd.getName.equalsIgnoreCase("test"){
        if (sender.hasPermission("MyPlugin.test") {
    // do stuff
    return true;
        } else {
    sender.sendMessage("You do not have permission!");
    return true; 
    }
    }
    return false;
    }
    That example assumes that you have defined a permission node called MyPlugin.test and a command called test.
     
  8. Offline

    ZeusAllMighty11

    As Envision said, this is what I would do.


    let's say my plugin is SmiteMe. If the player has a permisson called smiteme.me, it will //do stuff.

    PHP:
    public boolean onCommand(CommandSender senderCommand cmdString labelString[] args){
    if (
    cmd.getName.equalsIgnoreCase("smite") && player.hasPermission("SmiteMe.me"){
    // your code here
    return true;
    }else if(!(
    player.hasPermission("SmiteMe.me")){
    player.sendMessage("You can not smite yourself!");
    }
    Now in that plugin.yml you register it

    PHP:
    nameSmite
    description
    Smiteplayers
    author
    Zeus
    main
    package.package.package.class
    commands:
      
    smite:
        
    descriptionsmite yourself
        
    default: true
    permissions
    :
      
    SmiteMe.me
     
    wesley27 and AKS JEFFREY like this.
  9. Let me just explain plain and clear what I've learned so far about permissions:

    - You don't have to define them in plugin.yml, you can just check if the player has the permission (not required to belong to your plugin either), example (code):
    Code:
    if(sender.hasPermission("any.permission.node"))
    {
        // sender has that permission
    }

    - Defining permission in the command in plugin.yml will automatically check if player has permission for that command, you don't need to check it yourself, example (plugin.yml):
    Code:
    commands:
      mycmd:
        permission: my.node.for.this
        permission-message: You don't have <permission>
    The permission-message is optional to customize the denial message.


    - Defining permission in the permissions in plugin.yml will register the permission allowing you to set a default value for it, this is useful if you want certain permission to be automatically set to certain players... like all players (true), operators (op), all non-operator players (non-op), and nobody (false), example (plugin.yml):
    Code:
    permissions:
      my.permission.node:
        default: op
    You can also register permissions inside code by creating a new Permission(), setting stuff for it and you can use getPluginManager() to add the permission to the server.


    These are only available for node permissions from the Bukkit API, if you want access to groups and stuff, those are features added by permission plugins and you must hook in the plugin to get groups and stuff... or you can just use Vault which provides an interface for most plugins.



    ZeusAllMighty11
    You mis-placed default there, commands don't have default :p


    EDIT: theguynextdoor
    It must be something newly added because I didn't see that before, good to know... I've also changed this ^ so it doesn't confuse people.
     
    Bobit and kag359six like this.
  10. Offline

    theguynextdoor

    I would like so say this; Digi said pretty much all, except

    With you can send a custom message when the permission is not met, by using another line called permission-message, so your plugin.yml might look like:
    Code:
    commands:
          example:
              description: This is an example command.
              usage: /<command>
              permission: example.permission
              permission-message: You don't have <permission>
    *taken from the plugin tutorial previously linked*
     
  11. Offline

    ZeusAllMighty11

  12. Offline

    kag359six

    Is it possible to create groups using arrays? Like, an array of players, and all the players in that particular array can have a certain permission? Like an array named admins and all players within it have admin rights?
     
    grummbunger likes this.
  13. kag359six
    Why would you want to do that ? Are you making a permission managing plugin ? There are plugins that already add groups... and like I said, if you want to use groups from permission managing plugins, you'll have to import that plugin or use Vault's permissions interface...

    It's pointlessly complicated with groups tough, just provide a permission node and server administrators will place it in whatever group they desire, if they even use groups that is.
     
Thread Status:
Not open for further replies.

Share This Page