Search in sources :

Example 6 with CommandException

use of pl.themolka.arcade.command.CommandException in project Arcade2 by ShootGame.

the class TeamsGame method autoJoinTeam.

// 
// Team Management
// 
public void autoJoinTeam(GamePlayer player) throws CommandException {
    Team smallestTeam = null;
    for (Team team : this.teamsById.values()) {
        if (team.isParticipating()) {
            if (smallestTeam != null) {
                double first = smallestTeam.getOnlineMembers().size() / smallestTeam.getMaxPlayers();
                double second = team.getOnlineMembers().size() / team.getMaxPlayers();
                if (first > second) {
                    smallestTeam = team;
                }
            } else {
                smallestTeam = team;
            }
        }
    }
    if (smallestTeam == null) {
        throw new CommandException("No teams were found!");
    }
    Team join = smallestTeam;
    if (!player.hasPermission("arcade.command.join.overfill") && join.isFull()) {
        throw new CommandException("Teams are full! " + ChatColor.GOLD + "Only " + ChatColor.BOLD + "VIP" + ChatColor.RESET + ChatColor.GOLD + "s can join full teams.");
    } else if (this.getTeam(player) != null && this.getTeam(player).equals(join)) {
        throw new CommandException("You already joined " + join.getName() + ".");
    } else if (join.isOverfilled()) {
        throw new CommandException("Teams are overfilled!");
    }
    this.joinTeam(player, join);
}
Also used : CommandException(pl.themolka.arcade.command.CommandException)

Example 7 with CommandException

use of pl.themolka.arcade.command.CommandException 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 8 with CommandException

use of pl.themolka.arcade.command.CommandException in project Arcade2 by ShootGame.

the class TeamCommands method forceCommand.

public void forceCommand(Sender sender, String username, String teamId) {
    GamePlayer player = this.fetchPlayer(username);
    Team team = this.fetchTeam(teamId);
    if (team.contains(player)) {
        throw new CommandException(player.getUsername() + " is already member of " + team.getName() + ".");
    }
    team.joinForce(player);
    sender.sendSuccess(player.getUsername() + " has been moved to " + team.getName() + ".");
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) CommandException(pl.themolka.arcade.command.CommandException)

Example 9 with CommandException

use of pl.themolka.arcade.command.CommandException in project Arcade2 by ShootGame.

the class TeamCommands method renameCommand.

public void renameCommand(Sender sender, String teamId, String name) {
    Team team = this.fetchTeam(teamId);
    if (name == null) {
        throw new CommandException("New name not given.");
    } else if (name.length() > Team.NAME_MAX_LENGTH) {
        throw new CommandException("Name too long (greater than " + Team.NAME_MAX_LENGTH + " characters).");
    } else if (team.getName().equals(name)) {
        throw new CommandException("Already named '" + team.getName() + "'.");
    }
    Team oldState = new Team(team);
    team.setName(name);
    this.callEditEvent(team, oldState, TeamEditEvent.Reason.RENAME);
    sender.sendSuccess(oldState.getName() + " has been renamed to " + team.getName() + ".");
}
Also used : CommandException(pl.themolka.arcade.command.CommandException)

Example 10 with CommandException

use of pl.themolka.arcade.command.CommandException in project Arcade2 by ShootGame.

the class TeamCommands method clearCommand.

// 
// Commands
// 
public void clearCommand(Sender sender, String teamId) {
    Team team = this.fetchTeam(teamId);
    if (team.isObservers()) {
        throw new CommandException("Cannot clear observers.");
    }
    Observers observers = this.game.getMatch().getObservers();
    int result = 0;
    for (GamePlayer player : new ArrayList<>(team.getOnlineMembers())) {
        observers.joinForce(player);
        result++;
    }
    if (result > 0) {
        sender.sendSuccess(team.getName() + " has been cleared (" + result + " players) and moved to " + observers.getName() + ".");
    } else {
        sender.sendError("No players to clear.");
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) Observers(pl.themolka.arcade.match.Observers) ArrayList(java.util.ArrayList) CommandException(pl.themolka.arcade.command.CommandException)

Aggregations

CommandException (pl.themolka.arcade.command.CommandException)10 GamePlayer (pl.themolka.arcade.game.GamePlayer)3 ArrayList (java.util.ArrayList)2 CommandInfo (pl.themolka.arcade.command.CommandInfo)2 GeneralCommands (pl.themolka.arcade.command.GeneralCommands)2 Game (pl.themolka.arcade.game.Game)2 OfflineMap (pl.themolka.arcade.map.OfflineMap)2 Countdown (pl.themolka.arcade.task.Countdown)2 ChatColor (org.bukkit.ChatColor)1 CycleStartEvent (pl.themolka.arcade.cycle.CycleStartEvent)1 Observers (pl.themolka.arcade.match.Observers)1