Allow ArgReader to handle case where arg is null.

This commit is contained in:
Olof Larsson 2013-09-19 16:20:17 +02:00
parent 91f9ec7c0c
commit cf5751333e
2 changed files with 14 additions and 9 deletions

View File

@ -514,7 +514,8 @@ public abstract class MCommand
public <T> T arg(int idx, ArgReader<T> argReader) public <T> T arg(int idx, ArgReader<T> argReader)
{ {
return this.arg(idx, argReader, null); String str = this.arg(idx);
return this.arg(str, argReader);
} }
public <T> T arg(int idx, ArgReader<T> argReader, T defaultNotSet) public <T> T arg(int idx, ArgReader<T> argReader, T defaultNotSet)
@ -536,7 +537,8 @@ public abstract class MCommand
public <T> T argConcatFrom(int idx, ArgReader<T> argReader) public <T> T argConcatFrom(int idx, ArgReader<T> argReader)
{ {
return this.argConcatFrom(idx, argReader, null); String str = this.argConcatFrom(idx);
return this.arg(str, argReader);
} }
public <T> T argConcatFrom(int idx, ArgReader<T> argReader, T defaultNotSet) public <T> T argConcatFrom(int idx, ArgReader<T> argReader, T defaultNotSet)
@ -547,18 +549,22 @@ public abstract class MCommand
// Core & Other // Core & Other
public <T> T arg(String str, ArgReader<T> argReader, T defaultNotSet) public <T> T arg(ArgReader<T> argReader)
{
return this.arg(null, argReader);
}
public <T> T arg(String str, ArgReader<T> argReader)
{ {
if (str == null) return defaultNotSet;
ArgResult<T> result = argReader.read(str, this.sender); ArgResult<T> result = argReader.read(str, this.sender);
if (result.hasErrors()) this.msg(result.getErrors()); if (result.hasErrors()) this.msg(result.getErrors());
return result.getResult(); return result.getResult();
} }
public <T> T arg(ArgReader<T> argReader) public <T> T arg(String str, ArgReader<T> argReader, T defaultNotSet)
{ {
ArgResult<T> result = argReader.read(null, this.sender); if (str == null) return defaultNotSet;
if (result.hasErrors()) this.msg(result.getErrors()); return this.arg(str, argReader);
return result.getResult();
} }
} }

View File

@ -22,7 +22,6 @@ import com.massivecraft.mcore.util.Txt;
import com.massivecraft.mcore.xlib.gson.Gson; import com.massivecraft.mcore.xlib.gson.Gson;
import com.massivecraft.mcore.xlib.gson.JsonElement; import com.massivecraft.mcore.xlib.gson.JsonElement;
import com.massivecraft.mcore.xlib.gson.JsonObject; import com.massivecraft.mcore.xlib.gson.JsonObject;
import com.massivecraft.mcore.xlib.gson.JsonSyntaxException;
public class Coll<E> implements CollInterface<E> public class Coll<E> implements CollInterface<E>
{ {