Search in sources :

Example 1 with CycleCountdown

use of pl.themolka.arcade.cycle.CycleCountdown in project Arcade2 by ShootGame.

the class GeneralCommands method cycle.

// 
// /cycle command
// 
@CommandInfo(name = "cycle", description = "Cycle to next map", usage = "[seconds]", permission = "arcade.command.cycle")
public void cycle(Sender sender, CommandContext context) {
    int paramSeconds = context.getParamInt(0, (int) CycleCountdown.DEFAULT_DURATION.getSeconds());
    OfflineMap nextMap = this.plugin.getGames().getQueue().getNextMap();
    if (nextMap == null) {
        String reason = "The map queue is empty.";
        if (sender.hasPermission("arcade.command.setnext")) {
            reason += " Set next map using /setnext <map...>.";
        }
        throw new CommandException(reason);
    }
    CycleCommandEvent commandEvent = new CycleCommandEvent(this.plugin, sender, context, nextMap);
    this.plugin.getEventBus().publish(commandEvent);
    if (commandEvent.isCanceled()) {
        return;
    }
    int seconds = paramSeconds;
    if (seconds < 3) {
        seconds = 3;
    }
    CycleStartEvent startEvent = new CycleStartEvent(this.plugin, nextMap, seconds);
    this.plugin.getEventBus().publish(startEvent);
    this.plugin.getGames().setNextRestart(false);
    Game game = this.plugin.getGames().getCurrentGame();
    if (game != null) {
        for (Countdown countdown : game.getRunningCountdowns()) {
            countdown.cancelCountdown();
        }
        CycleCountdown countdown = this.plugin.getGames().getCycleCountdown();
        countdown.cancelCountdown();
        countdown.setDuration(Duration.ofSeconds(seconds));
        countdown.countSync();
    }
}
Also used : Game(pl.themolka.arcade.game.Game) CycleStartEvent(pl.themolka.arcade.cycle.CycleStartEvent) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) OfflineMap(pl.themolka.arcade.map.OfflineMap) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) Countdown(pl.themolka.arcade.task.Countdown) RestartCountdown(pl.themolka.arcade.game.RestartCountdown)

Example 2 with CycleCountdown

use of pl.themolka.arcade.cycle.CycleCountdown in project Arcade2 by ShootGame.

the class GeneralCommands method recycle.

// 
// /recycle command
// 
@CommandInfo(name = "recycle", description = "Re-cycle current map", usage = "[seconds]", permission = "arcade.command.cycle")
public void recycle(Sender sender, CommandContext context) {
    if (this.plugin.getGames().getCurrentGame() == null) {
        throw new CommandException("Game is not running right now.");
    }
    MapQueue queue = this.plugin.getGames().getQueue();
    queue.setNextMap(this.plugin.getGames().getCurrentGame().getMap().getMapInfo());
    CycleCommandEvent commandEvent = new CycleCommandEvent(this.plugin, sender, context, queue.getNextMap());
    this.plugin.getEventBus().publish(commandEvent);
    if (commandEvent.isCanceled()) {
        return;
    }
    int seconds = context.getParamInt(0, (int) CycleCountdown.DEFAULT_DURATION.getSeconds());
    if (seconds < 3) {
        seconds = 3;
    }
    CycleStartEvent startEvent = new CycleStartEvent(this.plugin, queue.getNextMap(), seconds);
    this.plugin.getEventBus().publish(startEvent);
    this.plugin.getGames().setNextRestart(false);
    Game game = this.plugin.getGames().getCurrentGame();
    if (game != null) {
        for (Countdown countdown : game.getRunningCountdowns()) {
            countdown.cancelCountdown();
        }
        CycleCountdown countdown = this.plugin.getGames().getCycleCountdown();
        countdown.cancelCountdown();
        countdown.setDuration(Duration.ofSeconds(seconds));
        countdown.countSync();
    }
}
Also used : Game(pl.themolka.arcade.game.Game) MapQueue(pl.themolka.arcade.map.queue.MapQueue) CycleStartEvent(pl.themolka.arcade.cycle.CycleStartEvent) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) Countdown(pl.themolka.arcade.task.Countdown) RestartCountdown(pl.themolka.arcade.game.RestartCountdown)

Example 3 with CycleCountdown

use of pl.themolka.arcade.cycle.CycleCountdown in project Arcade2 by ShootGame.

the class MatchGame method onCycleCountdownAutoStart.

@Handler(priority = Priority.LOWEST)
public void onCycleCountdownAutoStart(MatchEndedEvent event) {
    if (!this.isAutoCycle()) {
        // auto cycle is disabled
        return;
    }
    GameManager games = event.getPlugin().getGames();
    Countdown countdown;
    if (games.isNextRestart()) {
        countdown = games.getRestartCountdown();
        if (!countdown.isTaskRunning()) {
            ((RestartCountdown) countdown).setDefaultDuration();
        }
    } else {
        countdown = games.getCycleCountdown();
        if (!countdown.isTaskRunning()) {
            ((CycleCountdown) countdown).setDefaultDuration();
        }
    }
    if (!countdown.isTaskRunning()) {
        countdown.countSync();
    }
}
Also used : GameManager(pl.themolka.arcade.game.GameManager) RestartCountdown(pl.themolka.arcade.game.RestartCountdown) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) RestartCountdown(pl.themolka.arcade.game.RestartCountdown) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) Countdown(pl.themolka.arcade.task.Countdown) Handler(net.engio.mbassy.listener.Handler)

Aggregations

CycleCountdown (pl.themolka.arcade.cycle.CycleCountdown)3 RestartCountdown (pl.themolka.arcade.game.RestartCountdown)3 Countdown (pl.themolka.arcade.task.Countdown)3 CycleStartEvent (pl.themolka.arcade.cycle.CycleStartEvent)2 Game (pl.themolka.arcade.game.Game)2 Handler (net.engio.mbassy.listener.Handler)1 GameManager (pl.themolka.arcade.game.GameManager)1 OfflineMap (pl.themolka.arcade.map.OfflineMap)1 MapQueue (pl.themolka.arcade.map.queue.MapQueue)1