Permissions Help

Discussion in 'Plugin Development' started by iiHeroo, Sep 18, 2013.

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

    iiHeroo

    I want it to return with the message "You don't have permission to execute this command!" if they don't have permission, but it returns with this, http://gyazo.com/7ee4a7baa1517889fda76770ed9585de, here's my code,
    Code:java
    1. if(commandLabel.equalsIgnoreCase("hi")) {
    2. if(player.hasPermission("hi.hi")){
    3. } else {
    4. player.sendMessage(ChatColor.RED + "You don't have permission to execute this command!");
    5. }
    6. }
    7.  
    8. return false;
    9.  
    10. }
    11. }
     
  2. Offline

    mydeblob

    iiHeroo iiHeroo Bukkit will automatically send that message if you have it enabled in the plugin.yml. Make sure your plugin.yml looks something like this
    Code:
    name: {$PluginName}
    main: {$PackageName}.{$MainClass}
    version: {$VersionNumber}
    commands:
      hi:
          description: This says hi.
          usage: /<command>
          permission: hi.hi
          permission-message: You don't have <permission>
    Change the plugin.yml line "permission-message" to what you want it to say if they do not have permission. The one above will say "You don't have hi.hi"

    iiHeroo
    Forgot to tag you

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

    iiHeroo

    mydeblob so if I put a permission in the plugin.yml, it will give me that?
     
  4. Offline

    mydeblob

    iiHeroo
    Yup. Bukkit has implemented a lot of nice things like this. I edited my original post to explain it a bit more.
     
    iiHeroo likes this.
  5. Offline

    iiHeroo


    Is there a way to still have "children" if I create a permission outside the plugin.yml ? If so, how ?
     
  6. Offline

    mydeblob

    iiHeroo
    What do you mean by children? Explain that a bit more and I can answer.
     
  7. Offline

    iiHeroo


    In the plugin.yml of course ;p, look here, around line 91-92: http://pastie.org/8337830
     
  8. Offline

    mydeblob

    iiHeroo
    Yea, if I'm understanding you're question correctly it is still possible. You can always have permissions outside of the plugin.yml as bukkit will always check if there is any permission node in the plugin.yml or the code before doing the command.
     
  9. Offline

    iiHeroo


    okay thanks ! If you could give me an example of the code, you don't need to if you don't want to, I can always find out somehow. But thanks for the help !
     
  10. Offline

    mydeblob

    iiHeroo
    Code:java
    1. if(player.hasPermission(lol.hi)){
    2. if(cmd.getName().equalsIgnorecase("troll")){
    3. player.setHealth(0);
    4. }
    5. }

    What this does is it first checks if the player has permission to do the command. If they do not it will tell them the "I'm sorry but you do not have permission to use this command, if you beleive this is an error contact an admin" if they do have permission it will kill them
     
  11. Offline

    iiHeroo


    No, I mean like, creating a permission outside the plugin.yml :p
     
  12. Offline

    mydeblob

    iiHeroo
    That's what I did. Doing
    if(player.hasPermission(some.permissionhere)){}
    is creating a new permission for your plugin
     
  13. Offline

    iiHeroo

    Oh lol,but thats the same code I used to check if he had the permission that was in the config
     
  14. Offline

    1Rogue

    Random thought, did you register your permissions within the plugin.yml?

    Code:
    permissions:
        example.*:
            default: op
            children:
                example.node: true
                example.admin: true
     
  15. Offline

    iiHeroo

    Yeah
     
  16. Offline

    1Rogue


    Can you include your entire onCommand then?

    Edit: Don't bind a permission to your command within the plugin.yml. Just do the checking within the plugin yourself, register the permissions only in the plugin.yml, then you can use the message.
     
  17. Offline

    iiHeroo

    On mobile so can't use code option here's onCommand code
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
     
Thread Status:
Not open for further replies.

Share This Page