Solved Commands not working

Discussion in 'Plugin Development' started by ProMCKingz, Aug 18, 2014.

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

    ProMCKingz

    Why does the following code not work?
    Code:java
    1. public class Commands implements CommandExecutor{
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    4.  
    5. String prefix = ChatColor.DARK_AQUA + ("Wardrobe+");
    6. Player p = (Player) sender;
    7.  
    8. if(cmd.getName().equalsIgnoreCase("Wardrobe")){
    9. if(!sender.hasPermission("wardrobe.command.main")){
    10. sender.sendMessage(ChatColor.DARK_RED + "You do not have the permission");
    11. return true;
    12. }
    13. if(args.length == 0){
    14. String V = Bukkit.getServer().getBukkitVersion();
    15. p.sendMessage(prefix + ChatColor.AQUA + "Wardrobe Made by:" + ChatColor.GREEN + "" + ChatColor.BOLD + " ProMCKingz");
    16. p.sendMessage(prefix + ChatColor.RED + "Version 1.0");
    17. p.sendMessage(prefix + ChatColor.DARK_PURPLE + V);
    18. return true;
    19. }
    20. else if (args.length == 1) {
    21. if (args[0].equalsIgnoreCase("open")) {
    22. if (!sender.hasPermission("wardrobe.command.open")) {
    23. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
    24. return true;
    25. }
    26. p.openInventory(CompassPort.getCompassInventory());
    27. }
    28. else if (args[0].equalsIgnoreCase("reload")) {
    29. if (!sender.hasPermission("wardrobe.command.reload")) {
    30. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
    31. return true;
    32. }
    33. Bukkit.getServer().getPluginManager().getPlugin("WardrobePlus").reloadConfig();
    34. p.sendMessage(prefix + ChatColor.GREEN + "Was reloaded!");
    35. Bukkit.getServer().broadcastMessage(prefix + ChatColor.GREEN + "Was reloaded by " + ChatColor.RED + p);
    36. }
    37. }
    38. return true;
    39. }
    40. return true;
    41. }
    42.  
    43. }
     
  2. Offline

    masons123456

    ProMCKingz We need more info then "doesn't work". Is there an error? Could you send us the full class? Are you properly registering the command?

    One potential issue I see is that you cast sender to Player before checking if that is truly the case.
     
  3. Offline

    Lactem

    What do you mean by "not work?"
     
  4. Offline

    ProMCKingz

    masons123456 Lactem
    I apologies,
    So what I mean by not working is that when i type the command it only shows the plugin.yml registry.
    Which in my case is /wardrobe <arguments>.
    Also I have not registered my events, how do i do that? I thought you only do that with Listeners.
     
  5. Offline

    Lactem

    By that he means setting the CommandExecuter in onEnable().
     
  6. Offline

    ProMCKingz

    Lactem
    So this?
    Code:java
    1. getServer().getPluginManager().registerEvents(new InteractListener(), this);
     
  7. Offline

    masons123456

    ProMCKingz No, registering the executor for your command.
     
  8. Offline

    ProMCKingz

    So this,
    Code:java
    1. getCommand("wardrobe").setExecutor(new Commands());
     
  9. Offline

    Lactem

    Commands commands = new Commands();
    getCommand("wardrobe").setExecutor(commands);

    EDIT: The Pro beat me. :p
     
    masons123456 likes this.
  10. Offline

    masons123456

    ProMCKingz Yes. but your command isn't "TC", it's Wardrobe.
     
  11. Offline

    ProMCKingz

    Lactem
    LOL,
    but wouldnt that destroy my other arguments?

    masons123456
    Yes, I rushed that by copying from another plugin of mine.
    However im still unsure if it would destroy my other arguments

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

    masons123456

  13. Offline

    Lactem

    Destroy your other arguments?
     
  14. Offline

    ProMCKingz

    Lactem
    What I mean is, that I have arguments inside there like /wardrobe reload etc..
    would it not destroy them? and only keep /wardrobe
     
  15. Offline

    masons123456

    ProMCKingz Change getCommand("TC") to getCommand("Wardobe"), your cmd is not apart of the args
     
  16. Offline

    ProMCKingz

    masons123456
    Yes I have, and have edited it above.
    And thanks for your help, let's hope it works!

    Lactem
    WOW!
    Your quite popular in the bukkit community!
    over 6K downloads on each plugin! :D

    masons123456 Lactem
    Thanks so much!
    New to coding, and have learnt alot from you guys!
    Given full credit once the plugin is released!
    Thanks again,
    ProMCKingz
    [Solved]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page