Search in sources :

Example 1 with PlotAnalysis

use of com.plotsquared.core.plot.expiration.PlotAnalysis in project PlotSquared by IntellectualSites.

the class Done method onCommand.

@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
    Location location = player.getLocation();
    final Plot plot = location.getPlotAbs();
    if ((plot == null) || !plot.hasOwner()) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
        return false;
    }
    PlotDoneEvent event = this.eventDispatcher.callDone(plot);
    if (event.getEventResult() == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Done"));
        return true;
    }
    boolean force = event.getEventResult() == Result.FORCE;
    if (!force && !plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DONE)) {
        player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
        return false;
    }
    if (DoneFlag.isDone(plot)) {
        player.sendMessage(TranslatableCaption.of("done.done_already_done"));
        return false;
    }
    if (plot.getRunning() > 0) {
        player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
        return false;
    }
    plot.addRunning();
    player.sendMessage(TranslatableCaption.of("web.generating_link"), Template.of("plot", plot.getId().toString()));
    final Settings.Auto_Clear doneRequirements = Settings.AUTO_CLEAR.get("done");
    if (ExpireManager.IMP == null || doneRequirements == null) {
        finish(plot, player, true);
        plot.removeRunning();
    } else {
        this.hybridUtils.analyzePlot(plot, new RunnableVal<>() {

            @Override
            public void run(PlotAnalysis value) {
                plot.removeRunning();
                boolean result = value.getComplexity(doneRequirements) <= doneRequirements.THRESHOLD;
                finish(plot, player, result);
            }
        });
    }
    return true;
}
Also used : Plot(com.plotsquared.core.plot.Plot) PlotDoneEvent(com.plotsquared.core.events.PlotDoneEvent) PlotAnalysis(com.plotsquared.core.plot.expiration.PlotAnalysis) Settings(com.plotsquared.core.configuration.Settings) Location(com.plotsquared.core.location.Location)

Aggregations

Settings (com.plotsquared.core.configuration.Settings)1 PlotDoneEvent (com.plotsquared.core.events.PlotDoneEvent)1 Location (com.plotsquared.core.location.Location)1 Plot (com.plotsquared.core.plot.Plot)1 PlotAnalysis (com.plotsquared.core.plot.expiration.PlotAnalysis)1