package mondocommand;

import java.util.List;

import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 * Represents all the arguments that go along with a call.
 * @author James Crasta
 *
 */
public class CallInfo {
    private final CommandSender sender;
    private final Player player;
    private final String baseCommand;
    private final SubCommand subCommand;
    private final String replyPrefix;

    private List<String> args;

    /**
     * Create a new CallInfo representing one command invocaion.
     * @param sender The CommandSender who invoked this (can be a console)
     * @param player The Player who invoked this (will be null if a console)
     * @param baseCommand The label of the base command being executed (for reference)
     * @param subCommand The SubCommand we're executing.
     * @param args The command arguments.
     * @param format 
     */
    public CallInfo(CommandSender sender, Player player, String baseCommand, SubCommand subCommand, List<String> args, FormatConfig formatter) {
        Validate.notNull(sender);
        Validate.notEmpty(baseCommand);
        Validate.notNull(subCommand);
        this.sender = sender;
        this.player = player;
        this.args = args;
        this.baseCommand = baseCommand;
        this.subCommand = subCommand;
        this.replyPrefix = ChatMagic.colorize(formatter.getReplyPrefix());
    }

    /**
     * Get the player who invoked this. Can be null if running at the console.
     * @return a Player, or null if this is a console command
     */
    public Player getPlayer() {
        return player;
    }

    /**
     * Get the CommandSender who invoked this.
     * @return a CommandSender.
     */
    public CommandSender getSender() {
        return sender;
    }

    /**
     * Get a specific argument.
     * @param index The argument number.
     * @return The specific argument requested.
     */
    public String getArg(int index) {
        return this.args.get(index);
    }

    /**
     * Get the whole list of command arguments.
     * @return List of arguments.
     */
    public List<String> getArgs() {
        return this.args;
    }

    /**
     * How many arguments we got.
     * @return Number of arguments
     */
    public int numArgs() {
        return this.args.size();
    }

    /**
     * Get the base command which was called for this sub-command call.
     * @return A base command string.
     */
    public String getBaseCommand() {
        return baseCommand;
    }

    /**
     * Get the SubCommand that invoked this call.
     * @return a SubCommand.
     */
    public SubCommand getSubCommand() {
        return subCommand;
    }

    /**
     * Respond to the call, interpolating colors and variables.
     * @param template A string template. see @class ColorMagic documentation.
     * @param args Zero or more arguments to interpolate the template
     */
    public void reply(String template, Object ... args) {
        if (replyPrefix.length() == 0) {
            ChatMagic.send(sender, template, args);
        } else {
            ChatMagic.send(sender, replyPrefix + template, args);
        }
    }

    /**
     * Reply to the sender with no formatting
     * @param message a simple string.
     */
    public void replySimple(String message) {
        sender.sendMessage(replyPrefix + message);
    }
}

@@ -40,16 +40,60 @@
 .List;%0A%0A
+import org.apache.commons.lang.StringUtils;%0A
 import o
@@ -125,16 +125,16 @@
 lidate;%0A
-
 import o
@@ -972,17 +972,65 @@
 m format
- 
+ter The formatter being used by our MondoCommand.
 %0A     */
@@ -2296,24 +2296,774 @@
 .args;%0A    %7D
+%0A    %0A    /**%0A     * Get an argument coerced into an int. %0A     * @param index the location in the arguments array.%0A     * @return The argumnt%0A     */%0A    public int getIntArg(int index) %7B%0A        return Integer.parseInt(getArg(index));%0A    %7D%0A    %0A    /**%0A     * Get all the arguments after the specified index joined into a single string.%0A     * %0A     * This is useful if one of your last arguments is a free-form text entry %0A     * (like for a chat message, or editing a sign/book text)%0A     * @param index The index to start at (inclusive)%0A     * @return A single string containing all the arguments til the end%0A     */%0A    public String getJoinedArgsAfter(int index) %7B%0A        return StringUtils.join(args.subList(index, args.size()), %22 %22);%0A    %7D
 %0A%0A    /**%0A  
@@ -3689,19 +3689,12 @@
 te. 
-s
+S
 ee 
-@class 
 Colo
@@ -3713,16 +3713,30 @@
 entation
+ for more info
 .%0A     *
@@ -3799,16 +3799,47 @@
 emplate%0A
+     * @see ChatMagic#colorize%0A
      */%0A

Add a method which gets integer and joined arguments from a call.