Solved No Permission statement not working?

Discussion in 'Plugin Development' started by IAreKyleW00t, Mar 7, 2014.

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

    IAreKyleW00t

    So, I know how to check if a user has Permission or not...
    Code:java
    1. if (!sender.hasPermission(cmd.getPermission())) {
    2. ...
    3. }


    But whenever I put stuff within that block, it'll never be executed if the user doesn't have permission. I want to be able to properly output information, as well as a "no permission" message but I fails to do that regardless of that I do.

    plugin.yml
    Code:
    commands:
      ban:
        description: Ban a player
        usage: /ban <player> [reason]
        permission: skaianet.admin.ban
    permissions:
      skaianet.admin.ban:
        description: Allows the player to ban another player
    Main Class:
    Code:java
    1. this.getCommand("ban").setExecutor(new BanCmd(this));


    BanCmd Class:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if (!sender.hasPermission(cmd.getPermission())) {
    4. sender.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    5. return true;
    6. }
    7. ...
    8. }


    The problem I'm having is that if a player doens't have permission, it spits out that generic "I'm sorry, but you do not have permission to ..." message instead of the custom one I set. The entire block between the If-statement isn't even executed. How can I fix this, or (if this fits better), how should i set up Permission handling? I've tried looking through the forum for similar answers, but I haven't found anything...
     
  2. Offline

    97WaterPolo

    Try something like

    If command is /test && sender.has permission
    {
    Write code to be done here
    }else
    {
    Send player a message.
    }
     
  3. Offline

    ShadowLAX

    IAreKyleW00t Try
    Code:java
    1. if (player.hasPermission("permission") {
     
  4. Offline

    IAreKyleW00t

    I guess I should try using...
    Code:java
    1. if (sender.hasPermission(cmd.getPermission()) == false) {
    2. ...
    3. }
    4.  


    EDIT: That didn't fix it. It still throws that same generic error message.

    How come if I use "my.permission.*" it won't pick up on "my.permission.ban"? Am I missing something with that as well?
     
  5. Offline

    Wolfey

    Are you dispatching any command with that?
     
  6. Offline

    IAreKyleW00t

    What do you mean exactly?
     
  7. Offline

    Wizehh

    You cannot use wildcards in literals.
     
  8. Offline

    Wolfey

    When you perform your /ban command, what exactly is happening? Is the player performing some command?
     
  9. Offline

    IAreKyleW00t

    The player specified is getting banned... but that's not the problem. I'm wondering why it's not throwing a specific error message that I specify when the player doesn't have permission.



    Would I need to do that through plugin.yml and set the children in order to do that?
     
  10. Offline

    Wolfey

    Let me see if I'm understanding your problem, you're getting a different message then the one you put in?

    In that case, how exactly is the player getting banned? Are they performing another command when they write /ban? Maybe something like this?
    Code:java
    1. player.performCommand("someOtherBanCommand");
     
  11. Offline

    IAreKyleW00t


    No... I just want to output a custom No Permission message if the user doesn't have permission to use a command. That's all. That has absolutely nothing to do with the problem.
     
  12. Offline

    Wolfey

    IAreKyleW00t
    Code:java
    1. if(!player.hasPermission("permission")) {
    2. player.sendMessage("no permission");
    3. return true;
    4. }

    ....?
     
  13. Offline

    IAreKyleW00t

    That's the problem I'm having... for some reason it doesn't send the "no permission" message. I have
    Code:
    if (!sender.hasPermission(cmd.getPermission())) {
        sender.sendMessage(ChatColor.RED + "You don't have permission to do that.");
        return true;
    }
    But it refuses to send that message. Instead, it outputs the default "I'm sorry, but you do not have permission to..."
     
  14. Offline

    dpajd

    Remove the permission from the command in the plugin.yml
     
  15. Offline

    IAreKyleW00t


    This fixed the issue, but would I still set wildcards in the plugin.yml? (Eg: skaianet.admin.*)
     
  16. Offline

    dpajd

    IAreKyleW00t
    Using inheritances:
    Code:java
    1. name: Inferno
    2. version: 1.4.1
    3. description: This plugin is so 31337. You can set yourself on fire.
    4. # We could place every author in the authors list, but chose not to for illustrative purposes
    5. # Also, having an author distinguishes that person as the project lead, and ensures their
    6. # name is displayed first
    7. author: CaptainInflamo
    8. authors: [Cogito, verrier, EvilSeph]
    9. website: [url]http://forums.bukkit.org/threads/MyPlugin.31337/[/url]
    10.  
    11. main: com.captaininflamo.bukkit.inferno.Inferno
    12. database: false
    13. depend: [NewFire, FlameWire]
    14.  
    15. commands:
    16. flagrate:
    17. description: Set yourself on fire.
    18. aliases: [combust_me, combustMe]
    19. permission: inferno.flagrate
    20. usage: Syntax error! Simply type /&lt;command&gt; to ignite yourself.
    21. burningdeaths:
    22. description: List how many times you have died by fire.
    23. aliases: [burning_deaths, burningDeaths]
    24. permission: inferno.burningdeaths
    25. usage: |
    26. /&lt;command&gt; [player]
    27. Example: /&lt;command&gt; - see how many times you have burned to death
    28. Example: /&lt;command&gt; CaptainIce - see how many times CaptainIce has burned to death
    29.  
    30. permissions:
    31. inferno.*:
    32. description: Gives access to all Inferno commands
    33. children:
    34. inferno.flagrate: true
    35. inferno.burningdeaths: true
    36. inferno.burningdeaths.others: true
    37. inferno.flagrate:
    38. description: Allows you to ignite yourself
    39. default: true
    40. inferno.burningdeaths:
    41. description: Allows you to see how many times you have burned to death
    42. default: true
    43. inferno.burningdeaths.others:
    44. description: Allows you to see how many times others have burned to death
    45. default: op
    46. children:
    47. inferno.burningdeaths: true
     
  17. Offline

    IAreKyleW00t

    I know, but because of the fact that I removed the permission from the command within plugin.yml, will that affect inheritance?
     
  18. Offline

    dpajd

    Well, I am not sure.
    But, something I am sure about:
    Code:
    permission-message: Message
    
    Will fix it if it does.
     
Thread Status:
Not open for further replies.

Share This Page