Solved Arguments after commands not working

Discussion in 'Plugin Development' started by Deathbyrussian, Feb 14, 2014.

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

    Deathbyrussian

    Hello everyone. I'm fairly new to Java and just started messing around with the Bukkit API yesterday. I'm trying to make a simple plugin just for practice.
    It's a very simple plugin and it's half working. All it does is returns a list of user commands on my server when you type /commands. There will be multiple pages of it, with 5 or so commands and their descriptions per page. Users will type /commands 2, /commands 3, etc. to get to the next page of commands. Here is the code:

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] nums)
        {
            if (cmd.getName().equalsIgnoreCase("commands"))
                {
                Player player = (Player) sender;
                if (nums.length == 0)
                    {
                        player.sendMessage(ChatColor.RED + "------ " + ChatColor.GREEN + "User Commands Page 1" + ChatColor.RED + " ------");
                        player.sendMessage(ChatColor.BLUE +"/tpa <playername> -" + ChatColor.WHITE + " Sends a player a request to teleport to them.\n"
                                + ChatColor.BLUE + "/home >homename> -" + ChatColor.WHITE + " Teleports you to the selected home.\n"
                                    + ChatColor.GREEN + "Type /commands 2 for the next page.");
                        return true;
                    }
                else if (nums[0] == "2")
                    {
                        player.sendMessage(ChatColor.RED + "------ " + ChatColor.GREEN + "User Commands Page 2" + ChatColor.RED + " ------");
                        player.sendMessage(ChatColor.BLUE +"/tpa playername - Sends a player a request to teleport to them.\n"
                                + ChatColor.BLUE + "/sethome <homename> -" + ChatColor.WHITE + "Sets a home with the name given. Name cannot start with number.");
                        return true;
                    }
                }
            return false;
        }
    }
    The plugin itself is running fine. When I type /commands, it returns what's in the if (nums.length == 0) area, which is what I want. But when I type /commands 2, it returns the "Usage" from the plugin.yml file. I've tried setting the String[] nums array to an int[] array, but that didn't work either.

    Any ideas as to what could be causing this? I know it's a very, very simple issue and there's probably a better way to do it (if there is please let me know).
     
  2. Offline

    Mmarz11

    Deathbyrussian You should use the equals(...) or equalsIgnoreCase(...) methods to compare Strings instead of ==. Change:
    to:
     
  3. Offline

    Deathbyrussian

    Gah, I knew it was something simple. I always make that specific error, too. Thank you!
     
Thread Status:
Not open for further replies.

Share This Page