Solved Command is just returning itself

Discussion in 'Plugin Development' started by Doubtstand, Aug 12, 2015.

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

    Doubtstand

    I have this code:

    Code:java
    1.  
    2. public class RankCommand implements CommandExecutor{
    3.  
    4. Main plugin;
    5.  
    6. public RankCommand(Main instance){
    7. plugin = instance;
    8. }
    9.  
    10. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    11. if(cmd.getName().equalsIgnoreCase("setrank")){
    12. if(args.length <= 1){
    13. sender.sendMessage(ChatColor.GRAY + "Please use " + ChatColor.YELLOW + "/setrank <player> <rank>" + ChatColor.GRAY + ".");
    14. return true;
    15. }
    16. if(args.length == 2){
    17.  
    18. Player target = Bukkit.getServer().getPlayer(args[0]);
    19.  
    20. if(target == null){
    21. sender.sendMessage(ChatColor.GRAY + "Could not find the player " + ChatColor.YELLOW + args[0]);
    22. return true;
    23. }
    24.  
    25. if(args[1].equalsIgnoreCase("user")){
    26. plugin.rank.put(target.getUniqueId(), "user");
    27. return true;
    28. }
    29.  
    30. if(args[1].equalsIgnoreCase("admin")){
    31. plugin.rank.put(target.getUniqueId(), "admin");
    32. return true;
    33. }
    34. }
    35. if(args.length > 2){
    36. sender.sendMessage(ChatColor.GRAY + "Please use " + ChatColor.YELLOW + "/setrank <player> <rank>" + ChatColor.GRAY + ".");
    37. return true;
    38. }
    39. }
    40. return true;
    41. }
    42. }
    43.  
    44.  


    And everytime I use the /setrank command, it returns "/setrank <player> <rank>".

    My plugin.yml:
    Code:java
    1.  
    2. name: RankTest
    3. main: me.stenterstal.pack.Main
    4. version: 1.0
    5. author: stenterstal
    6. commands:
    7. setrank:
    8. usage: /<command> <player> <rank>
    9. description: Applies a rank to the specific player.
    10.  


    Anyone that can help me with this?

    The goal of the code is to save the string "user" or "admin" bound to the players UUID in a hashmap so I don't have to use an external plugin.

    Thanks, Sten.
     
    Last edited: Aug 12, 2015
  2. Offline

    Corndogoz

    at the end you wrote return true; make that return false;
     
  3. Offline

    Doubtstand

    /setrank is still returning the usage in the plugin.yml
     
  4. Offline

    CoolDude53

    It returns the usage from the plugin.yml when the command returns false, so make sure you return true in the right places.
     
  5. Offline

    Corndogoz

    @CoolDude53 btw why do people put usage in the .yml? ive never seen it used
     
  6. Offline

    CoolDude53

    @Corndogoz To keep record what the arguments are whether they are required or not. You can't create a valid command without putting the usage in the plugin.yml.
     
Thread Status:
Not open for further replies.

Share This Page