Solved How do I create command aliases now?

Discussion in 'Plugin Development' started by FurmigaHumana, Nov 9, 2014.

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

    FurmigaHumana

    Its been a while since I last used the bukkit API and now im facing this little problem, I usually register command aliases in the plugin.yml like this:

    Code:java
    1. commands:
    2. creativecontrol:
    3. aliases: [cc, ccontrol]
    4. description: CreativeControl Commands
    5. usage: /creativecontrol help


    But it wont work anymore, this will crash the server with some sort of "/cc cant be an alias for it self" or something like that, I searched around but couldn't find any information about that, just that I had to use the new bukkit command structure, how do I do that?
     
  2. Offline

    ChipDev

  3. Offline

    MordorKing78

  4. Offline

    Regablith

    In addition to this, when making the command you need to check if(command.equalsBlahBlah || command.equalsBlahBlah)
     
  5. Offline

    adam753

    Regablith
    If you do it that way you don't get the benefit of aliases. You're describing checking the commandLabel, which gives the actual command name that was typed. Using command.getName() on the other hand will always give the de-aliased name of the command, so in this case it will always return "creativecontrol" even if the player typed /cc or /ccontrol. Anyway,

    FurmigaHumana
    That seems fine, I can't think what would be wrong. Could you post your onCommand method?
     
  6. Offline

    Regablith

    The last time I tried, you had to define the aliases when checking what command the player has typed as well as putting it under the aliases in the plugin.yml.
     
  7. Offline

    adam753

    I assume we're talking about the same thing here?

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. if(cmd.getName().equalsIgnoreCase("creativecontrol")) {
    4. //Good - will run no matter what alias was typed
    5. }
    6.  
    7. if(label.equalsIgnoreCase("creativecontrol")) {
    8. //Bad - will only run if "creativecontrol" was the exact thing typed
    9. }
    10. }
     
  8. Offline

    Regablith

    adam753
    I'm talking about label, not cmd. Sorry if I didn't explain that properly.
     
  9. Offline

    Rocoty

    Regablith Don't check the label. Then the entire point of defining aliases in the plugin.yml is completely gone.
     
    MordorKing78, Regablith and adam753 like this.
  10. Offline

    Regablith

    Okay, I understand now. Thank you.
     
  11. Offline

    FurmigaHumana


    Aha! Indentation problem, by default, netbeans uses 4 spaces for yml, plugin.yml uses only 2 spaces, dont know why this became a problem just with the aliases, as the command works just fine... nor even why just started happening now... anyway, problem solved.
     
Thread Status:
Not open for further replies.

Share This Page