Command Not Working

Discussion in 'Spigot Plugin Development' started by Technerder, Apr 28, 2017.

  1. after registering my command in my plugin.yml, the plugin loads properly, no errors in console, however if i try to run something like /teams help nothing happens. any ideas?

    code :
    Code (Text):
    package technerder.kurion.teams;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;

    public class Main extends JavaPlugin {

        public void TeamsCommand(CommandSender sender, Command cmd, String label, String[] args) {

            if (label.equalsIgnoreCase("teams")) {

                if (args[0].equalsIgnoreCase("create")) {

                    ScoreboardManager Manager = Bukkit.getScoreboardManager();
                    Scoreboard board = Manager.getNewScoreboard();
                    Team team = board.registerNewTeam(args[1]);
                    team.addEntry(sender.getName());
                    team.setAllowFriendlyFire(false);

                } else {

                    if (args[0].equalsIgnoreCase("disband")) {

                        Player player = (Player) sender;
                        Scoreboard scoreboard = player.getScoreboard();
                        for (Team team : scoreboard.getTeams()) {
                            team.unregister();
                        }

                    } else {

                        if (args[0].equalsIgnoreCase("join")) {

                        } else {

                            if (args[0].equalsIgnoreCase("leave")) {

                            } else {

                                if (args[0].equalsIgnoreCase("invite")) {

                                } else {

                                    if (args[0].equalsIgnoreCase("list")) {

                                    } else {

                                        if (args[0].equalsIgnoreCase("help")) {

                                            sender.sendMessage("---------------------------------------------------");
                                            sender.sendMessage("/teams create <team name>");
                                            sender.sendMessage("/teams disband");
                                            sender.sendMessage("/teams join <team name>");
                                            sender.sendMessage("/teams leave");
                                            sender.sendMessage("/teams invite <player>");
                                            sender.sendMessage("/teams list");
                                            sender.sendMessage("/teams help");
                                            sender.sendMessage("---------------------------------------------------");                                  
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
     
    • Funny Funny x 1
  2. NathanWolf

    Supporter

    Try renaming TeamsCommand to onCommand.

    The plugin manager can't magically know what method you want it to call. So you can either handle it via JavaPlugin.onCommand or by implementing and registering a CommandExecutor.
     
  3. ok so i have done that however it shows an extra line, how would i remove that?

    [20:13:09 INFO]: ---------------------------------------------------
    [20:13:09 INFO]: /teams create <team name>
    [20:13:09 INFO]: /teams disband
    [20:13:09 INFO]: /teams join <team name>
    [20:13:09 INFO]: /teams leave
    [20:13:09 INFO]: /teams invite <player>
    [20:13:09 INFO]: /teams list
    [20:13:09 INFO]: /teams help
    [20:13:09 INFO]: --------------------------------------------------
    [20:13:09 INFO]: /teams <--- this line is not supposed to be here
     
  4. Code (Text):
    return true
    instead of false
     
  5. Follow this video to learn how to properly make commands
     
  6. Change
    Code (Java):

      if (label.equalsIgnoreCase("teams")) {
     
    To
    Code (Java):

      if (cmd.equalsIgnoreCase("teams")) {