Command not working/not displaying aliases

Discussion in 'Plugin Development' started by xXMaTTHDXx, Nov 3, 2013.

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

    xXMaTTHDXx

    I have a command manager, when I type the command with no args it should send me a message with aliases about how I need to use the command, but it doesnt do that, then the command doesnt work in general...

    Code:
    package me.xXMaTTHDXx.TSRun;
     
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.TreeSet;
     
    import me.xXMaTTHDXx.TSRun.MessageManager.MessageType;
    import me.xXMaTTHDXx.TSRun.cmds.Create;
    import me.xXMaTTHDXx.TSRun.cmds.Delete;
    import me.xXMaTTHDXx.TSRun.cmds.Join;
    import me.xXMaTTHDXx.TSRun.cmds.Leave;
    import me.xXMaTTHDXx.TSRun.cmds.Lobby;
    import me.xXMaTTHDXx.TSRun.cmds.Reload;
    import me.xXMaTTHDXx.TSRun.cmds.SetLocation;
    import me.xXMaTTHDXx.TSRun.cmds.Start;
    import me.xXMaTTHDXx.TSRun.cmds.Stop;
    import me.xXMaTTHDXx.TSRun.cmds.TSRunCommand;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
     
        public class CommandManager implements CommandExecutor {
     
            private TreeSet<TSRunCommand> cmds = new TreeSet<TSRunCommand>();
     
            public void setup() {
                cmds.add(new Create());
                cmds.add(new Delete());
                cmds.add(new Start());
                cmds.add(new Stop());
                cmds.add(new Join());
                cmds.add(new Leave());
                cmds.add(new Reload());
                cmds.add(new SetLocation());
                cmds.add(new Lobby());
            }
     
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                if (!(sender instanceof Player)) {
                    MessageManager.getInstance().msg(sender, MessageType.BAD, "Only players can use TSRun!");
                    return true;
                }
     
                Player p = (Player) sender;
     
                if (cmd.getName().equalsIgnoreCase("tsrun")) {
                    if (args.length == 0) {
                        for (TSRunCommand mc : cmds) MessageManager.getInstance().msg(p, MessageType.INFO, "/tsrun " + aliases(mc) + " " + mc.getUsage() + " - " + mc.getMessage());
                        return true;
                    }
     
                    TSRunCommand c = getCommand(args[0]);
     
                    if (c == null) {
                        MessageManager.getInstance().msg(sender, MessageType.BAD, "That command doesn't exist!");
                        return true;
                    }
     
                    TreeSet<String> a = new TreeSet<String>(Arrays.asList(args));
                    a.remove(0);
                    args = a.toArray(new String[a.size()]);
     
                    c.onCommand(p, args);
     
                    return true;
                }
                return true;
            }
     
            private String aliases(TSRunCommand cmd) {
                String fin = "";
     
                for (String a : cmd.getAliases()) {
                    fin += a + " | ";
                }
     
                return fin.substring(0, fin.lastIndexOf(" | "));
            }
     
            private TSRunCommand getCommand(String name) {
                for (TSRunCommand cmd : cmds) if (cmd.getClass().getSimpleName().equalsIgnoreCase(name)) return cmd;
                return null;
            }
        }
     
  2. Offline

    Hoolean

    xXMaTTHDXx

    Full code? :)

    Perhaps you are not registering your CommandExecutor.
     
  3. Offline

    tyler53



    Hoolean, this is exactly like My Post Here

    I'm having the same problem, is it a problem with bukkit or how we are doing it?
     
  4. Offline

    xXMaTTHDXx

    Code:java
    1. package me.xXMaTTHDXx.TSRun;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Arrays;
    5. import java.util.TreeSet;
    6.  
    7. import me.xXMaTTHDXx.TSRun.MessageManager.MessageType;
    8. import me.xXMaTTHDXx.TSRun.cmds.Create;
    9. import me.xXMaTTHDXx.TSRun.cmds.Delete;
    10. import me.xXMaTTHDXx.TSRun.cmds.Join;
    11. import me.xXMaTTHDXx.TSRun.cmds.Leave;
    12. import me.xXMaTTHDXx.TSRun.cmds.Lobby;
    13. import me.xXMaTTHDXx.TSRun.cmds.Reload;
    14. import me.xXMaTTHDXx.TSRun.cmds.SetLocation;
    15. import me.xXMaTTHDXx.TSRun.cmds.Start;
    16. import me.xXMaTTHDXx.TSRun.cmds.Stop;
    17. import me.xXMaTTHDXx.TSRun.cmds.TSRunCommand;
    18.  
    19. import org.bukkit.command.Command;
    20. import org.bukkit.command.CommandExecutor;
    21. import org.bukkit.command.CommandSender;
    22. import org.bukkit.entity.Player;
    23.  
    24.  
    25. public class CommandManager implements CommandExecutor {
    26.  
    27. private TreeSet<TSRunCommand> cmds = new TreeSet<TSRunCommand>();
    28.  
    29. public void setup() {
    30. cmds.add(new Create());
    31. cmds.add(new Delete());
    32. cmds.add(new Start());
    33. cmds.add(new Stop());
    34. cmds.add(new Join());
    35. cmds.add(new Leave());
    36. cmds.add(new Reload());
    37. cmds.add(new SetLocation());
    38. cmds.add(new Lobby());
    39. }
    40.  
    41. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    42. if (!(sender instanceof Player)) {
    43. MessageManager.getInstance().msg(sender, MessageType.BAD, "Only players can use TSRun!");
    44. return true;
    45. }
    46.  
    47. Player p = (Player) sender;
    48.  
    49. if (cmd.getName().equalsIgnoreCase("tsrun")) {
    50. if (args.length == 0) {
    51. for (TSRunCommand mc : cmds) MessageManager.getInstance().msg(p, MessageType.INFO, "/tsrun " + aliases(mc) + " " + mc.getUsage() + " - " + mc.getMessage());
    52. return true;
    53. }
    54.  
    55. TSRunCommand c = getCommand(args[0]);
    56.  
    57. if (c == null) {
    58. MessageManager.getInstance().msg(sender, MessageType.BAD, "That command doesn't exist!");
    59. return true;
    60. }
    61.  
    62. TreeSet<String> a = new TreeSet<String>(Arrays.asList(args));
    63. a.remove(0);
    64. args = a.toArray(new String[a.size()]);
    65.  
    66. c.onCommand(p, args);
    67.  
    68. return true;
    69. }
    70. return true;
    71. }
    72.  
    73. private String aliases(TSRunCommand cmd) {
    74. String fin = "";
    75.  
    76. for (String a : cmd.getAliases()) {
    77. fin += a + " | ";
    78. }
    79.  
    80. return fin.substring(0, fin.lastIndexOf(" | "));
    81. }
    82.  
    83. private TSRunCommand getCommand(String name) {
    84. for (TSRunCommand cmd : cmds) if (cmd.getClass().getSimpleName().equalsIgnoreCase(name)) return cmd;
    85. return null;
    86. }
    87. }


    Thats the commandManager

    Main:
    Code:java
    1. package me.xXMaTTHDXx.TSRun;
    2.  
    3. import me.xXMaTTHDXx.TSRun.Listeners.BlockBreak;
    4. import me.xXMaTTHDXx.TSRun.Listeners.PlayerDeath;
    5. import me.xXMaTTHDXx.TSRun.Listeners.PlayerLeave;
    6. import me.xXMaTTHDXx.TSRun.Listeners.PlayerLoseHunger;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.plugin.Plugin;
    10. import org.bukkit.plugin.PluginManager;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class TSRun extends JavaPlugin{
    14. public static TSRun plugin;
    15.  
    16. public void onEnable(){
    17. getLogger().info("TSRun is enabled!");
    18.  
    19. Bukkit.getServer().getPluginManager().registerEvents(new SignManager(), this);
    20.  
    21. ArenaManager.getInstance().setupArenas();
    22.  
    23. CommandManager cm = new CommandManager();
    24. cm.setup();
    25. getCommand("tsrun").setExecutor(cm);
    26.  
    27. PluginManager pm = Bukkit.getServer().getPluginManager();
    28. pm.registerEvents(new BlockBreak(), this);
    29. pm.registerEvents(new PlayerDeath(), this);
    30. pm.registerEvents(new PlayerLeave(), this);
    31. pm.registerEvents(new PlayerLoseHunger(), this);
    32. }
    33.  
    34. public void onDisable(){
    35. getLogger().info("TSRun is disabled!");
    36. }
    37.  
    38.  
    39. public static Plugin getPlugin() {
    40. return Bukkit.getServer().getPluginManager().getPlugin("MagicBattle");
    41. }
    42. }
    43.  


    Hoolean

    Anyone?

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

    tyler53

    this still seems to be an issue that many people are having, I have no idea what is causing it, I have the issue even when not creating a custom class to manage commands, even the simplest plugin like I mentioned in my previous reply linking you to my thread.
     
  6. Offline

    xXMaTTHDXx

    This is really making me mad, I need this new plugin, well I hope someone fixes it.
     
  7. Offline

    tyler53

  8. Offline

    xXMaTTHDXx

Thread Status:
Not open for further replies.

Share This Page