Search in sources :

Example 6 with OfflineMap

use of pl.themolka.arcade.map.OfflineMap in project Arcade2 by ShootGame.

the class SimpleGameManager method fillDefaultQueue.

@Override
public void fillDefaultQueue() {
    Node node = this.plugin.getSettings().getData().child("queue");
    if (node == null) {
        node = Node.empty();
    }
    for (Node mapNode : node.children("map")) {
        String directory = mapNode.propertyValue("directory");
        String mapName = mapNode.getValue();
        OfflineMap map = null;
        if (directory != null) {
            map = this.plugin.getMaps().getContainer().getMapByDirectory(directory);
        } else if (mapName != null) {
            map = this.plugin.getMaps().getContainer().getMap(mapName);
        }
        if (map != null) {
            queue.addMap(map);
        }
    }
    this.postEvent(new MapQueueFillEvent(this.plugin, this.getQueue()));
}
Also used : MapQueueFillEvent(pl.themolka.arcade.map.queue.MapQueueFillEvent) Node(pl.themolka.arcade.dom.Node) OfflineMap(pl.themolka.arcade.map.OfflineMap)

Example 7 with OfflineMap

use of pl.themolka.arcade.map.OfflineMap in project Arcade2 by ShootGame.

the class MapCommands method mapInfo.

// 
// /mapinfo command
// 
@CommandInfo(name = { "mapinfo", "map" }, description = "Describe a map", flags = { "c", "current", "n", "next" }, usage = "[-current|-next|<map...>]", permission = "arcade.command.mapinfo", completer = "mapInfoCompleter")
public void mapInfo(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.plugin.getGames().getCurrentGame();
        if (game == null) {
            throw new CommandException("No game running right now.");
        }
        results.add(game.getMap().getMapInfo());
    } else if (paramNext) {
        OfflineMap next = this.plugin.getGames().getQueue().getNextMap();
        if (next == null) {
            throw new CommandException("The map queue is empty.");
        }
        results.add(next);
    } else {
        results.addAll(this.plugin.getMaps().findMap(paramMap));
    }
    if (results.isEmpty()) {
        throw new CommandException("No results found.");
    } else if (results.size() > 1) {
        sender.sendError("Found " + results.size() + " results. Displaying the best one...");
    }
    this.mapInfoDescribe(sender, results.get(0));
}
Also used : Game(pl.themolka.arcade.game.Game) OfflineMap(pl.themolka.arcade.map.OfflineMap) ArrayList(java.util.ArrayList)

Example 8 with OfflineMap

use of pl.themolka.arcade.map.OfflineMap in project Arcade2 by ShootGame.

the class CycleCountdown method onUpdate.

@Override
public void onUpdate(long seconds, long secondsLeft) {
    if (!this.plugin.getGames().getQueue().hasNextMap()) {
        this.cancelCountdown();
        return;
    } else if (!this.isPrintable(secondsLeft)) {
        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()));
    for (ArcadePlayer player : this.plugin.getPlayers()) {
        player.getPlayer().send(message);
    }
    this.plugin.getLogger().info(ChatColor.stripColor(message));
}
Also used : Game(pl.themolka.arcade.game.Game) ArcadePlayer(pl.themolka.arcade.session.ArcadePlayer) OfflineMap(pl.themolka.arcade.map.OfflineMap)

Example 9 with OfflineMap

use of pl.themolka.arcade.map.OfflineMap in project Arcade2 by ShootGame.

the class SimpleGameManager method cycle.

@Override
public void cycle(OfflineMap target) {
    Instant now = Instant.now();
    if (target == null) {
        OfflineMap next = this.getQueue().takeNextMap();
        if (next == null) {
            this.plugin.getLogger().severe("Map queue was empty");
            return;
        }
        target = next;
        // refill queue if it's empty
        if (!this.getQueue().hasNextMap()) {
            this.fillDefaultQueue();
        }
    }
    this.plugin.getLogger().info("Cycling to '" + target.getName() + "' from '" + target.getDirectory().getName() + "'...");
    try {
        Game oldGame = this.getCurrentGame();
        Game game = this.createGame(target);
        this.plugin.getEventBus().publish(new ServerCycleEvent(this.plugin, game, oldGame));
        if (this.currentGame != null) {
            this.destroyGame(this.getCurrentGame());
        }
        this.setCurrentGame(game);
        game.start();
        if (this.getGameId() >= this.getMaxGameId()) {
            this.setNextRestart(true);
        }
    } catch (DOMException ex) {
        this.plugin.getLogger().log(Level.SEVERE, "Could not cycle to '" + target.getName() + "': " + ex.toString());
        this.cycleNext();
        return;
    } catch (Throwable th) {
        this.plugin.getLogger().log(Level.SEVERE, "Could not cycle to '" + target.getName() + "'", th);
        this.cycleNext();
        return;
    }
    this.plugin.getLogger().info("Cycled in " + (Instant.now().toEpochMilli() - now.toEpochMilli()) + " ms.");
}
Also used : DOMException(pl.themolka.arcade.dom.DOMException) ServerCycleEvent(pl.themolka.arcade.cycle.ServerCycleEvent) Instant(java.time.Instant) OfflineMap(pl.themolka.arcade.map.OfflineMap)

Example 10 with OfflineMap

use of pl.themolka.arcade.map.OfflineMap 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)

Aggregations

OfflineMap (pl.themolka.arcade.map.OfflineMap)10 Game (pl.themolka.arcade.game.Game)7 ArrayList (java.util.ArrayList)3 Countdown (pl.themolka.arcade.task.Countdown)3 CommandException (pl.themolka.arcade.command.CommandException)2 CommandInfo (pl.themolka.arcade.command.CommandInfo)2 GeneralCommands (pl.themolka.arcade.command.GeneralCommands)2 CycleStartEvent (pl.themolka.arcade.cycle.CycleStartEvent)2 ArcadePlayer (pl.themolka.arcade.session.ArcadePlayer)2 Instant (java.time.Instant)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 BossBar (pl.themolka.arcade.bossbar.BossBar)1 CycleCountdown (pl.themolka.arcade.cycle.CycleCountdown)1 ServerCycleEvent (pl.themolka.arcade.cycle.ServerCycleEvent)1 DOMException (pl.themolka.arcade.dom.DOMException)1 Node (pl.themolka.arcade.dom.Node)1 GamePlayer (pl.themolka.arcade.game.GamePlayer)1 RestartCountdown (pl.themolka.arcade.game.RestartCountdown)1 MapQueueFillEvent (pl.themolka.arcade.map.queue.MapQueueFillEvent)1