Optimize auto trim + command cost/confirmation

This commit is contained in:
Jesse Boyd
2016-05-22 05:29:19 +10:00
parent e2182260d9
commit b8afbe8a00
16 changed files with 325 additions and 745 deletions

View File

@@ -271,7 +271,7 @@ public abstract class Command {
* @return
*/
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 0 || args[0] == null) {
if (this.parent == null) {
MainCommand.getInstance().help.displayHelp(player, null, 0);
@@ -537,4 +537,33 @@ public abstract class Command {
FAILURE,
SUCCESS
}
public void checkTrue(boolean mustBeTrue, C message, Object... args) {
if (!mustBeTrue) {
throw new CommandException(message, args);
}
}
public <T extends Object> T check(T object, C message, Object... args) {
if (object == null) {
throw new CommandException(message, args);
}
return object;
}
public static class CommandException extends RuntimeException {
private final Object[] args;
private final C message;
public CommandException(C message, Object... args) {
this.message = message;
this.args = args;
}
public void perform(PlotPlayer player) {
if (player != null && message != null) {
message.send(player, args);
}
}
}
}