mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-08-03 13:05:29 +02:00
Optimize auto trim + command cost/confirmation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user