Search in sources :

Example 6 with Countdown

use of pl.themolka.arcade.task.Countdown in project Arcade2 by ShootGame.

the class DevelopmentCommands method cycleNow.

// 
// /cyclenow command
// 
@CommandInfo(name = { "cyclenow" }, description = "Cycle now to the given map", flags = { "c", "current", "n", "next" }, usage = "<map...>", permission = "arcade.command.cyclenow")
public void cycleNow(Sender sender, CommandContext context) {
    boolean paramCurrent = context.hasFlag("c") || context.hasFlag("current");
    boolean paramNext = context.hasFlag("n") || context.hasFlag("next");
    String paramMap = context.getParams(0);
    List<OfflineMap> results = new ArrayList<>();
    if (paramCurrent || context.getArgs().length == 0) {
        Game game = this.development.getPlugin().getGames().getCurrentGame();
        if (game == null) {
            throw new CommandException("No game running right now.");
        }
        results.add(game.getMap().getMapInfo());
    } else if (paramNext) {
        OfflineMap next = this.development.getPlugin().getGames().getQueue().getNextMap();
        if (next == 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);
        }
        results.add(next);
    } else {
        results.addAll(this.development.getPlugin().getMaps().findMap(paramMap));
    }
    if (results.isEmpty()) {
        throw new CommandException("No results found.");
    } else if (results.size() > 1) {
        sender.sendError("Found " + results.size() + " results. Cycling to the best one...");
    }
    OfflineMap target = results.get(0);
    GeneralCommands.CycleCommandEvent commandEvent = new GeneralCommands.CycleCommandEvent(this.development.getPlugin(), sender, context, target);
    this.development.getPlugin().getEventBus().publish(commandEvent);
    if (!commandEvent.isCanceled()) {
        sender.sendSuccess("Cycling now to " + target.getName() + "...");
        Game game = this.development.getPlugin().getGames().getCurrentGame();
        for (Countdown countdown : game.getRunningCountdowns()) {
            countdown.cancelCountdown();
        }
        this.development.getPlugin().getGames().getCycleCountdown().cancelCountdown();
        this.development.getPlugin().getGames().cycle(target);
    }
}
Also used : Game(pl.themolka.arcade.game.Game) OfflineMap(pl.themolka.arcade.map.OfflineMap) ArrayList(java.util.ArrayList) GeneralCommands(pl.themolka.arcade.command.GeneralCommands) Countdown(pl.themolka.arcade.task.Countdown) CommandException(pl.themolka.arcade.command.CommandException) CommandInfo(pl.themolka.arcade.command.CommandInfo)

Example 7 with Countdown

use of pl.themolka.arcade.task.Countdown 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

Countdown (pl.themolka.arcade.task.Countdown)7 Game (pl.themolka.arcade.game.Game)6 CycleCountdown (pl.themolka.arcade.cycle.CycleCountdown)5 RestartCountdown (pl.themolka.arcade.game.RestartCountdown)5 CycleStartEvent (pl.themolka.arcade.cycle.CycleStartEvent)3 OfflineMap (pl.themolka.arcade.map.OfflineMap)3 CommandException (pl.themolka.arcade.command.CommandException)2 CommandInfo (pl.themolka.arcade.command.CommandInfo)2 GeneralCommands (pl.themolka.arcade.command.GeneralCommands)2 ArrayList (java.util.ArrayList)1 Handler (net.engio.mbassy.listener.Handler)1 GameManager (pl.themolka.arcade.game.GameManager)1 MapQueue (pl.themolka.arcade.map.queue.MapQueue)1