package se.ranzdo.bukkit.methodcommand;

import java.lang.reflect.Array;

import org.bukkit.command.CommandSender;


public class WildcardArgument extends CommandArgument {
	private boolean join;

	public WildcardArgument(Arg commandArgAnnotation, Class<?> argumentClass, ArgumentHandler<?> argumentHandler, boolean join) {
		super(commandArgAnnotation, argumentClass, argumentHandler);
		this.join = join;
	}
	
	public WildcardArgument(String name, String description, String def, String verifiers, Class<?> argumentClass, ArgumentHandler<?> handler, boolean join) {
		super(name, description, def, verifiers, argumentClass, handler);
		this.join = join;
	}
	
	@Override
	public Object execute(CommandSender sender, Arguments args) throws CommandError {
		if(!args.hasNext()) {
			Object o = getHandler().handle(sender, this, getDefault().equals(" ") ? "" : getDefault());
			if(join)
				return o;
			else {
				Object array = Array.newInstance(getArgumentClass(), 1);
				Array.set(array, 0, o);
				return array;
			}
		}
		
		if(join) {
			StringBuilder sb = new StringBuilder();
			
			while(args.hasNext())
				sb.append(" "+args.nextArgument());
			
			return getHandler().handle(sender, this, CommandUtil.escapeArgumentVariable(sb.toString()));
		}
		else {
			Object array = Array.newInstance(getArgumentClass(), args.over());
			
			for(int i = 0; i < args.over();i++)
				Array.set(array, i, getHandler().handle(sender, this, CommandUtil.escapeArgumentVariable(args.nextArgument())));
			
			return array;
		}
	}
	
	public boolean willJoin() {
		return join;
	}
}

@@ -1078,16 +1078,43 @@
 lder();%0A
+%09%09%09boolean hasRun = false;%0A
 %09%09%09%0A%09%09%09w
@@ -1133,17 +1133,37 @@
 sNext())
+ %7B
 %0A
+%09%09%09%09if(hasRun) %7B%0A%09
 %09%09%09%09sb.a
@@ -1190,24 +1190,105 @@
 rgument());%0A
+%09%09%09%09%7D else %7B%0A%09%09%09%09%09sb.append(args.nextArgument());%0A%09%09%09%09%09hasRun = true;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A
 %09%09%09%0A%09%09%09retur

Update WildcardArgument.java