Search in sources :

Example 16 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class LobbyCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    Player player = BaseCommand.requirePlayer(sender);
    if (player == null) {
        return true;
    }
    Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
    if (!currentGame.isPresent()) {
        player.sendMessage(ChatColor.RED + "You are not in a game");
        return true;
    }
    Game game = currentGame.get();
    Team playerTeam = game.getPlayerTeam(player.getUniqueId());
    if (playerTeam != null && !currentGame.get().acceptsPeople()) {
        player.sendMessage(ChatColor.RED + "The game does not allow people to leave at the moment, you can only leave public games when in the lobby.");
    } else {
        game.removePlayer(player.getUniqueId());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Game(com.ebicep.warlords.game.Game) Team(com.ebicep.warlords.game.Team)

Example 17 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class SpectateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    Player player = BaseCommand.requirePlayerOutsideGame(sender);
    if (player != null) {
        if (!Warlords.getGameManager().getGames().stream().anyMatch(e -> e.getGame() != null && e.getGame().acceptsSpectators())) {
            sender.sendMessage(ChatColor.RED + "There are no active games right now!");
            return true;
        }
        Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
        if (currentGame.isPresent() && currentGame.get().getPlayerTeam(player.getUniqueId()) != null) {
            sender.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
            return true;
        }
        openSpectateMenu(player);
        return true;
    }
    return true;
}
Also used : Menu(com.ebicep.warlords.menu.Menu) CommandSender(org.bukkit.command.CommandSender) BaseCommand(com.ebicep.warlords.commands.BaseCommand) Warlords(com.ebicep.warlords.Warlords) Player(org.bukkit.entity.Player) CommandExecutor(org.bukkit.command.CommandExecutor) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Game(com.ebicep.warlords.game.Game) GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Optional(java.util.Optional) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Material(org.bukkit.Material) Player(org.bukkit.entity.Player) Game(com.ebicep.warlords.game.Game)

Example 18 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class GameTargetCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    if (!command.testPermissionSilent(sender)) {
        sender.sendMessage("§cYou do not have permission to do that.");
        return true;
    }
    Collection<GameManager.GameHolder> gameInstances;
    if (args.length == 0) {
        WarlordsPlayer wp = BaseCommand.requireWarlordsPlayer(sender);
        if (wp == null) {
            return true;
        }
        gameInstances = getGames().stream().filter(e -> e.getGame() == wp.getGame()).collect(Collectors.toList());
        if (gameInstances.isEmpty()) {
            sender.sendMessage(ChatColor.RED + "Unable to find the game that your are in!");
        }
    } else {
        Set<GameManager.GameHolder> holder = new HashSet<>();
        gameInstances = holder;
        List<GameManager.GameHolder> matched = new ArrayList<>();
        for (String arg : args) {
            matched.clear();
            for (GameManager.GameHolder h : getGames()) {
                Game game = h.getGame();
                if ("*".equals(arg) || h.getName().equalsIgnoreCase(arg) || h.getMap().name().equalsIgnoreCase(arg) || (game != null && game.getGameMode().name().equalsIgnoreCase(arg)) || (game != null && game.getGameId().toString().equalsIgnoreCase(arg))) {
                    matched.add(h);
                }
            }
            if (matched.isEmpty()) {
                sender.sendMessage(ChatColor.RED + "Unable to find: " + arg);
                continue;
            }
            holder.addAll(matched);
        }
    }
    this.doAction(sender, gameInstances);
    return true;
}
Also used : Game(com.ebicep.warlords.game.Game) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameManager(com.ebicep.warlords.game.GameManager)

Example 19 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class GameTerminateCommand method doAction.

@Override
protected void doAction(CommandSender sender, Collection<GameHolder> gameInstances) {
    sender.sendMessage(ChatColor.RED + "DEV:" + ChatColor.GRAY + " Requesting engine to terminate games...");
    if (gameInstances.isEmpty()) {
        sender.sendMessage(ChatColor.RED + "No valid targets found!");
        return;
    }
    for (GameHolder holder : gameInstances) {
        Game game = holder.getGame();
        if (game == null) {
            sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not active now");
            continue;
        }
        if (holder.getGame().isFrozen()) {
            holder.getGame().clearFrozenCause();
        }
        Optional<PlayingState> state = game.getState(PlayingState.class);
        if (!state.isPresent()) {
            sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not in playing state, instead it is in " + game.getState().getClass().getSimpleName());
        } else {
            sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "Terminating game...");
            game.setNextState(new EndState(game, null));
        }
    }
    sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + "Game has been terminated. Warping back to lobby...");
}
Also used : GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Game(com.ebicep.warlords.game.Game) PlayingState(com.ebicep.warlords.game.state.PlayingState) EndState(com.ebicep.warlords.game.state.EndState)

Example 20 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class BaseCommand method requireGame.

@Nullable
public static Game requireGame(@Nonnull CommandSender sender, @Nullable String name) {
    Player p = requirePlayer(sender, name);
    if (p == null) {
        return null;
    }
    Optional<Game> playerGame = Warlords.getGameManager().getPlayerGame(((Player) sender).getUniqueId());
    if (!playerGame.isPresent()) {
        sender.sendMessage(ChatColor.RED + "You are not in a game!");
        return null;
    }
    return playerGame.get();
}
Also used : WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) Player(org.bukkit.entity.Player) Game(com.ebicep.warlords.game.Game) Nullable(javax.annotation.Nullable)

Aggregations

Game (com.ebicep.warlords.game.Game)25 Team (com.ebicep.warlords.game.Team)15 ChatColor (org.bukkit.ChatColor)13 Warlords (com.ebicep.warlords.Warlords)12 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)12 Nonnull (javax.annotation.Nonnull)12 Nullable (javax.annotation.Nullable)12 Player (org.bukkit.entity.Player)11 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)9 java.util (java.util)8 GameAddon (com.ebicep.warlords.game.GameAddon)7 Utils (com.ebicep.warlords.util.warlords.Utils)7 ScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler)6 PacketUtils (com.ebicep.warlords.util.bukkit.PacketUtils)6 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)6 Location (org.bukkit.Location)6 WarlordsGameTriggerWinEvent (com.ebicep.warlords.events.WarlordsGameTriggerWinEvent)5 GameHolder (com.ebicep.warlords.game.GameManager.GameHolder)5 SimpleScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler)5 PlayingState (com.ebicep.warlords.game.state.PlayingState)5