a warning about aliases in bukkit.yml

Discussion in 'Plugin Development' started by MeneXia, Feb 26, 2012.

Thread Status:
Not open for further replies.
  1. Potential code for checking whether the command is a certain String can render aliases in bukkit.yml useless.

    There was a guy on the #bukkit IRC named rumblez, and he pointed out this flaw in which I tested further.

    In the bukkit.yml, there's a section called "aliases" where you can assign alternate names for base commands. Here's an example: http://pastebin.com/m10FMD8i

    So I added a new alias like so.
    PHP:
    aliases:
      
    icanhasbukkit:
      - 
    version
      newdynafishcommand
    :
      - 
    dynafish
    This makes a user able to use /newdynafishcommand instead of /dynafish.

    However, some plugin devs put a base command check in their onCommand() method of their plugins:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String zhf, String[] args) {
    2. if (zhf.equalsIgnoreCase("dynafish" || zhf.equalsIgnoreCase("df")) {
    3. // execute what you want here...
    4. return true;
    5. }
    6. return false;
    7. }

    Thus, when one executes the new alias provided from bukkit.yml, the code will not execute because the base command is not "dynafish" or "df."

    Possible ways to fix this?
    1. Simply use this check instead:
    Code:java
    1. cmd.getName().equals("dynafish");

    2.Write commands in another class which implements CommandExecutor, then you will not have to check the string whether the base command is what you want, as you can be able to do this in the main class:
    Code:java
    1. getCommand("dynafish").setExecutor(new DynaFishCommand(this));
     
  2. checking the command itself should work or doesn't it?
    Code:
    cmd.getName().equals("dynafish")
     
  3. That should work, because the alias links back to the command itself.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    Personally, I still can't think of an use case for the alias string, but because of this, there exits more of a chance for someone to code a plugin that does not behave properly.
     
    MeneXia likes this.
Thread Status:
Not open for further replies.

Share This Page