use of com.plotsquared.core.util.task.RunnableVal3 in project PlotSquared by IntellectualSites.
the class MainCommand method onCommand.
public static boolean onCommand(final PlotPlayer<?> player, String... args) {
final EconHandler econHandler = PlotSquared.platform().econHandler();
if (args.length >= 1 && args[0].contains(":")) {
String[] split2 = args[0].split(":");
if (split2.length == 2) {
// Ref: c:v, this will push value to the last spot in the array
// ex. /p h:2 SomeUsername
// > /p h SomeUsername 2
String[] tmp = new String[args.length + 1];
tmp[0] = split2[0];
tmp[args.length] = split2[1];
if (args.length >= 2) {
System.arraycopy(args, 1, tmp, 1, args.length - 1);
}
args = tmp;
}
}
try {
getInstance().execute(player, args, new RunnableVal3<>() {
@Override
public void run(final Command cmd, final Runnable success, final Runnable failure) {
if (cmd.hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
PlotArea area = player.getApplicablePlotArea();
if (area != null && econHandler.isEnabled(area)) {
PlotExpression priceEval = area.getPrices().get(cmd.getFullId());
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (econHandler.getMoney(player) < price) {
if (failure != null) {
failure.run();
}
return;
}
}
if (success != null) {
success.run();
}
});
return;
}
PlotArea area = player.getApplicablePlotArea();
if (area != null && econHandler.isEnabled(area)) {
PlotExpression priceEval = area.getPrices().get(cmd.getFullId());
double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != 0d && econHandler.getMoney(player) < price) {
if (failure != null) {
failure.run();
}
return;
}
}
if (success != null) {
success.run();
}
}
}, new RunnableVal2<>() {
@Override
public void run(Command cmd, CommandResult result) {
// Post command stuff!?
}
}).thenAccept(result -> {
// TODO: Something with the command result
});
} catch (CommandException e) {
e.perform(player);
}
// Always true
return true;
}
use of com.plotsquared.core.util.task.RunnableVal3 in project PlotSquared by IntellectualSites.
the class Clear method execute.
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length != 0) {
sendUsage(player);
return CompletableFuture.completedFuture(false);
}
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
Result eventResult = this.eventDispatcher.callClear(plot).getEventResult();
if (eventResult == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Clear"));
return CompletableFuture.completedFuture(true);
}
if (plot.getVolume() > Integer.MAX_VALUE) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
return CompletableFuture.completedFuture(true);
}
boolean force = eventResult == Result.FORCE;
checkTrue(force || plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.clear"), TranslatableCaption.of("permission.no_plot_perms"));
checkTrue(plot.getRunning() == 0, TranslatableCaption.of("errors.wait_for_timer"));
checkTrue(force || !Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot) || Permissions.hasPermission(player, "plots.continue"), TranslatableCaption.of("done.done_already_done"));
confirm.run(this, () -> {
if (Settings.Teleport.ON_CLEAR) {
plot.getPlayersInPlot().forEach(playerInPlot -> plot.teleportPlayer(playerInPlot, TeleportCause.COMMAND_CLEAR, result -> {
}));
}
BackupManager.backup(player, plot, () -> {
final long start = System.currentTimeMillis();
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> {
plot.getPlotModificationManager().unlink();
TaskManager.runTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (DoneFlag.isDone(plot)) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
}
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(AnalysisFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
}
player.sendMessage(TranslatableCaption.of("working.clearing_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), Template.of("plot", plot.getId().toString()));
});
});
if (!result) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
} else {
plot.addRunning();
}
});
}, null);
return CompletableFuture.completedFuture(true);
}
Aggregations