Solved command not working

Discussion in 'Plugin Development' started by vhbob, Dec 9, 2015.

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

    vhbob

    hello, my command will not work and says an internal error occoured. please help me and let me know what is wrong
    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                if (command.getName().equalsIgnoreCase("sh")) {
                    String s = args[1];
                    if (s.equalsIgnoreCase("test")) {
                        p.sendMessage("test");
                    }
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Only players can issue this command!");
            }
            return false;
        }
     
  2. Offline

    BrickBoy55

    @vhbob First of all, if all your command is doing is sending a message, there is no reason to see if it's a player first, and just use sender.sendMessage("<your message here>");

    Second of all (this doesnt really change anything), but you can just use if (args[1].equalsIgnoreCase("<blah>") { }

    If you are trying to make the command /sh test, it should be args[0], not args[1].

    Hope I helped!
     
  3. Offline

    Zombie_Striker

    @vhbob
    You got to be kidding me:
    You create the player before its YOUR command. So no matter what command it is, there will be this instance of player.

    YOU DID NOT CHECK IF THERE ARE ANY ARGS. Also, args start at 0. And it's better to just check if args[1].equals "test" instead of creating S
     
  4. Offline

    vhbob

Thread Status:
Not open for further replies.

Share This Page