Search in sources :

Example 1 with WarmupConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.WarmupConfig in project Nucleus by NucleusPowered.

the class AbstractCommand method setupWarmup.

@SuppressWarnings("unchecked")
private ContinueMode setupWarmup(final Player src, CommandContext args) {
    if (bypassWarmup) {
        return ContinueMode.CONTINUE;
    }
    // Get the warmup time.
    int warmupTime = getWarmup(src);
    if (warmupTime <= 0) {
        return ContinueMode.CONTINUE;
    }
    // We create a task that executes the command at a later time. Because
    // we already know we have permission,
    // we can skip those checks.
    Task.Builder tb = Sponge.getScheduler().createTaskBuilder().delay(warmupTime, TimeUnit.SECONDS).execute(new CostCancellableTask(plugin, src, getCost(src, args)) {

        @Override
        public void accept(Task task) {
            src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("warmup.end"));
            plugin.getWarmupManager().removeWarmup(src.getUniqueId());
            onExecute((T) src, args);
        }
    }).name("Command Warmup - " + src.getName());
    // Run an async command async, of course!
    if (isAsync) {
        tb.async();
    }
    // Add the warmup to the service so we can cancel it if we need to.
    plugin.getWarmupManager().addWarmup(src.getUniqueId(), tb.submit(plugin));
    // Tell the user we're warming up.
    src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("warmup.start", Util.getTimeStringFromSeconds(warmupTime)));
    WarmupConfig wc = Nucleus.getNucleus().getWarmupConfig();
    if (wc.isOnMove() && wc.isOnCommand()) {
        src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("warmup.both"));
    } else if (wc.isOnMove()) {
        src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("warmup.onMove"));
    } else if (wc.isOnCommand()) {
        src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("warmup.onCommand"));
    }
    // Sponge should think the command was run successfully.
    return ContinueMode.STOP_SUCCESS;
}
Also used : CostCancellableTask(io.github.nucleuspowered.nucleus.internal.CostCancellableTask) Task(org.spongepowered.api.scheduler.Task) WarmupConfig(io.github.nucleuspowered.nucleus.modules.core.config.WarmupConfig) CostCancellableTask(io.github.nucleuspowered.nucleus.internal.CostCancellableTask)

Aggregations

CostCancellableTask (io.github.nucleuspowered.nucleus.internal.CostCancellableTask)1 WarmupConfig (io.github.nucleuspowered.nucleus.modules.core.config.WarmupConfig)1 Task (org.spongepowered.api.scheduler.Task)1