Search in sources :

Example 6 with Game

use of pl.themolka.arcade.game.Game 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 7 with Game

use of pl.themolka.arcade.game.Game in project Arcade2 by ShootGame.

the class GeneralCommands method restart.

// 
// /restart command
// 
@CommandInfo(name = "restart", description = "Cycle to next map", flags = { "f", "force" }, usage = "[-force] [seconds]", permission = "arcade.command.restart")
public void restart(Sender sender, CommandContext context) {
    int seconds = context.getParamInt(0, (int) RestartCountdown.DEFAULT_DURATION.getSeconds());
    if (seconds < 3) {
        seconds = 3;
    }
    boolean force = context.hasFlag("f") || context.hasFlag("force");
    CycleCommandEvent event = new CycleCommandEvent(this.plugin, sender, context, force);
    this.plugin.getEventBus().publish(event);
    if (event.isCanceled()) {
        return;
    }
    this.plugin.getGames().setNextRestart(true);
    Game game = this.plugin.getGames().getCurrentGame();
    if (game != null) {
        for (Countdown countdown : game.getRunningCountdowns()) {
            countdown.cancelCountdown();
        }
        RestartCountdown countdown = this.plugin.getGames().getRestartCountdown();
        countdown.cancelCountdown();
        countdown.setDuration(Duration.ofSeconds(seconds));
        countdown.countSync();
    }
}
Also used : Game(pl.themolka.arcade.game.Game) RestartCountdown(pl.themolka.arcade.game.RestartCountdown) CycleCountdown(pl.themolka.arcade.cycle.CycleCountdown) Countdown(pl.themolka.arcade.task.Countdown) RestartCountdown(pl.themolka.arcade.game.RestartCountdown)

Example 8 with Game

use of pl.themolka.arcade.game.Game in project Arcade2 by ShootGame.

the class MapCommands method setNext.

// 
// /setnext command
// 
@CommandInfo(name = { "setnext", "sn" }, description = "Set next map in the queue", flags = { "a", "after", "c", "current", "r", "restart" }, usage = "[-after] [-current|-restart|<map...>]", permission = "arcade.command.setnext", completer = "setNextCompleter")
public void setNext(Sender sender, CommandContext context) {
    boolean paramAfter = context.hasFlag("a") || context.hasFlag("after");
    boolean paramCurrent = context.hasFlag("c") || context.hasFlag("current");
    boolean paramRestart = context.hasFlag("r") || context.hasFlag("restart");
    String paramMap = context.getParams(0);
    if (paramRestart) {
        this.plugin.getGames().setNextRestart(true);
        throw new CommandException(this.plugin.getServerName() + " will be restarted after this game.");
    }
    List<OfflineMap> results = new ArrayList<>();
    if (paramCurrent) {
        Game game = this.plugin.getGames().getCurrentGame();
        if (game == null) {
            throw new CommandException("No game running right now.");
        }
        results.add(game.getMap().getMapInfo());
    } else if (paramMap != null) {
        results.addAll(this.plugin.getMaps().findMap(paramMap));
    } else {
        throw new CommandUsageException("You need to type map name, use -current or -restart flag");
    }
    if (results.isEmpty()) {
        throw new CommandException("No results found.");
    } else if (results.size() > 1) {
        sender.sendError("Found " + results.size() + " results. Setting next the best one...");
    }
    this.setNextMap(sender, results.get(0), !paramAfter);
}
Also used : Game(pl.themolka.arcade.game.Game) OfflineMap(pl.themolka.arcade.map.OfflineMap) ArrayList(java.util.ArrayList)

Example 9 with Game

use of pl.themolka.arcade.game.Game in project Arcade2 by ShootGame.

the class DevelopmentCommands method recycleNow.

// 
// /recyclenow command
// 
@CommandInfo(name = { "recyclenow" }, description = "Re-cycle now current map", permission = "arcade.command.cyclenow")
public void recycleNow(Sender sender, CommandContext context) {
    if (this.development.getPlugin().getGames().getCurrentGame() == null) {
        throw new CommandException("Game is not running right now.");
    }
    OfflineMap target = this.development.getPlugin().getGames().getCurrentGame().getMap().getMapInfo();
    GeneralCommands.CycleCommandEvent commandEvent = new GeneralCommands.CycleCommandEvent(this.development.getPlugin(), sender, context, target);
    this.development.getPlugin().getEventBus().publish(commandEvent);
    if (commandEvent.isCanceled()) {
        return;
    }
    CycleStartEvent startEvent = new CycleStartEvent(this.development.getPlugin(), target, 0);
    this.development.getPlugin().getEventBus().publish(startEvent);
    this.development.getPlugin().getGames().setNextRestart(false);
    Game game = this.development.getPlugin().getGames().getCurrentGame();
    if (game != null) {
        for (Countdown countdown : game.getRunningCountdowns()) {
            countdown.cancelCountdown();
        }
        sender.sendSuccess("Re-cycling now to " + target.getName() + "...");
        this.development.getPlugin().getGames().cycle(target);
    }
}
Also used : Game(pl.themolka.arcade.game.Game) CycleStartEvent(pl.themolka.arcade.cycle.CycleStartEvent) OfflineMap(pl.themolka.arcade.map.OfflineMap) 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 10 with Game

use of pl.themolka.arcade.game.Game in project Arcade2 by ShootGame.

the class CycleCountdown method onTick.

@Override
public void onTick(long ticks) {
    if (!this.plugin.getGames().getQueue().hasNextMap()) {
        this.cancelCountdown();
        return;
    } else if (this.getProgress() > 1) {
        return;
    }
    OfflineMap nextMap = this.plugin.getGames().getQueue().getNextMap();
    Game game = this.plugin.getGames().getCurrentGame();
    if (game == null) {
        return;
    }
    String message = this.getPrintMessage(this.getCycleMessage(nextMap.getName()));
    BossBar bossBar = this.getBossBar();
    bossBar.setProgress(Percentage.finite(this.getProgress()));
    bossBar.setText(new TextComponent(message));
    for (ArcadePlayer online : this.plugin.getPlayers()) {
        GamePlayer player = online.getGamePlayer();
        if (player != null) {
            bossBar.addPlayer(player, BAR_PRIORITY);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Game(pl.themolka.arcade.game.Game) ArcadePlayer(pl.themolka.arcade.session.ArcadePlayer) GamePlayer(pl.themolka.arcade.game.GamePlayer) OfflineMap(pl.themolka.arcade.map.OfflineMap) BossBar(pl.themolka.arcade.bossbar.BossBar)

Aggregations

Game (pl.themolka.arcade.game.Game)22 OfflineMap (pl.themolka.arcade.map.OfflineMap)7 Countdown (pl.themolka.arcade.task.Countdown)6 GamePlayer (pl.themolka.arcade.game.GamePlayer)5 ArrayList (java.util.ArrayList)4 EventHandler (org.bukkit.event.EventHandler)4 CycleCountdown (pl.themolka.arcade.cycle.CycleCountdown)4 RestartCountdown (pl.themolka.arcade.game.RestartCountdown)4 CycleStartEvent (pl.themolka.arcade.cycle.CycleStartEvent)3 ArcadePlayer (pl.themolka.arcade.session.ArcadePlayer)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Location (org.bukkit.Location)2 BossBar (pl.themolka.arcade.bossbar.BossBar)2 CommandException (pl.themolka.arcade.command.CommandException)2 CommandInfo (pl.themolka.arcade.command.CommandInfo)2 GeneralCommands (pl.themolka.arcade.command.GeneralCommands)2 Handler (net.engio.mbassy.listener.Handler)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1 PlayerDeathEvent (org.bukkit.event.entity.PlayerDeathEvent)1