Search in sources :

Example 1 with GameHolder

use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.

the class BotManager method sendStatusMessage.

public static void sendStatusMessage(boolean onQuit) {
    if (!Warlords.serverIP.equals("51.81.49.127")) {
        return;
    }
    DateFormat dateFormat = new SimpleDateFormat("hh:mm aa");
    dateFormat.setTimeZone(TimeZone.getTimeZone("EST"));
    EmbedBuilder eb = new EmbedBuilder().setTitle("Server Status", null).setColor(3066993).setFooter(dateFormat.format(new Date()) + " EST");
    eb.setDescription("**Players Online**: " + (onQuit ? Bukkit.getOnlinePlayers().size() - 1 : Bukkit.getOnlinePlayers().size()) + "\n");
    eb.appendDescription("**Players In Game**: " + Warlords.getGameManager().getPlayerCount() + "\n");
    eb.appendDescription("**Players Waiting in lobby**: " + Warlords.getGameManager().getPlayerCountInLobby() + "\n");
    for (GameHolder holder : Warlords.getGameManager().getGames()) {
        Game game = holder.getGame();
        if (game == null) {
            eb.appendDescription("**Game**: " + holder.getMap().getMapName() + " Inactive\n");
        } else {
            if (game.getState() instanceof PreLobbyState) {
                PreLobbyState state = (PreLobbyState) game.getState();
                if (!state.hasEnoughPlayers()) {
                    eb.appendDescription("**Game**: " + game.getMap().getMapName() + " Lobby - Waiting for players" + "\n");
                } else {
                    eb.appendDescription("**Game**: " + game.getMap().getMapName() + " Lobby - " + state.getTimeLeftString() + " Left" + "\n");
                }
            } else if (game.getState() instanceof PlayingState) {
                OptionalInt timeLeft = WinAfterTimeoutOption.getTimeLeft(game);
                String time = Utils.formatTimeLeft(timeLeft.isPresent() ? timeLeft.getAsInt() : (System.currentTimeMillis() - game.createdAt()) / 1000);
                String word = timeLeft.isPresent() ? " Left" : " Elapsed";
                eb.appendDescription("**Game**: " + game.getMap().getMapName() + " - " + time + word + " - " + game.getPoints(Team.BLUE) + ":" + game.getPoints(Team.RED) + "\n");
            } else {
                eb.appendDescription("**Game**: Ending" + "\n");
            }
        }
    }
    StringBuilder stringBuilder = new StringBuilder("**Parties**: ");
    Warlords.partyManager.getParties().forEach(party -> stringBuilder.append(party.getLeaderName()).append(" (").append(party.getPartyPlayers().size()).append("), "));
    stringBuilder.setLength(stringBuilder.length() - 1);
    eb.appendDescription(stringBuilder);
    MessageEmbed messageEmbed = eb.build();
    getTextChannelCompsByName(compGamesServerStatusChannel).ifPresent(textChannel -> {
        if (compStatusMessage == null) {
            textChannel.sendMessageEmbeds(messageEmbed).queue(m -> compStatusMessage = m);
        } else if (textChannel.getLatestMessageId().equals(compStatusMessage.getId())) {
            compStatusMessage.editMessageEmbeds(messageEmbed).queue();
        } else {
            compStatusMessage.delete().queue();
            textChannel.sendMessageEmbeds(messageEmbed).queue(m -> compStatusMessage = m);
        }
    });
    getTextChannelWL2ByName(wl2ServerStatusChannel).ifPresent(textChannel -> {
        if (wl2StatusMessage == null) {
            textChannel.sendMessageEmbeds(messageEmbed).queue(m -> wl2StatusMessage = m);
        } else if (textChannel.getLatestMessageId().equals(wl2StatusMessage.getId())) {
            wl2StatusMessage.editMessageEmbeds(messageEmbed).queue();
        } else {
            wl2StatusMessage.delete().queue();
            textChannel.sendMessageEmbeds(messageEmbed).queue(m -> wl2StatusMessage = m);
        }
    });
}
Also used : Message(net.dv8tion.jda.api.entities.Message) LoginException(javax.security.auth.login.LoginException) Utils(com.ebicep.warlords.util.warlords.Utils) java.util(java.util) JDA(net.dv8tion.jda.api.JDA) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Team(com.ebicep.warlords.game.Team) PlayingState(com.ebicep.warlords.game.state.PlayingState) WinAfterTimeoutOption(com.ebicep.warlords.game.option.WinAfterTimeoutOption) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) Guild(net.dv8tion.jda.api.entities.Guild) Game(com.ebicep.warlords.game.Game) PreLobbyState(com.ebicep.warlords.game.state.PreLobbyState) JDABuilder(net.dv8tion.jda.api.JDABuilder) GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) BukkitTask(org.bukkit.scheduler.BukkitTask) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) DateFormat(java.text.DateFormat) Bukkit(org.bukkit.Bukkit) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) PreLobbyState(com.ebicep.warlords.game.state.PreLobbyState) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Game(com.ebicep.warlords.game.Game) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PlayingState(com.ebicep.warlords.game.state.PlayingState) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with GameHolder

use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.

the class GameKillCommand method doAction.

@Override
protected void doAction(CommandSender sender, Collection<GameHolder> gameInstances) {
    sender.sendMessage(ChatColor.RED + "DEV:" + ChatColor.GRAY + " Requesting engine to kill games...");
    if (gameInstances.isEmpty()) {
        sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + "No valid targets found!");
        return;
    }
    for (GameHolder holder : gameInstances) {
        if (holder.getGame() == null) {
            sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not active now");
            continue;
        }
        holder.forceEndGame();
        sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "Terminated");
    }
}
Also used : GameHolder(com.ebicep.warlords.game.GameManager.GameHolder)

Example 3 with GameHolder

use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.

the class GameListCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    if (!sender.hasPermission("warlords.game.list")) {
        sender.sendMessage("§cYou do not have permission to do that.");
        return true;
    }
    for (GameHolder holder : Warlords.getGameManager().getGames()) {
        StringBuilder message = new StringBuilder();
        message.append(ChatColor.GRAY).append("[").append(ChatColor.AQUA).append(holder.getName()).append(ChatColor.GRAY).append("|").append(ChatColor.AQUA).append(toTitleHumanCase(holder.getMap().name()));
        Game game = holder.getGame();
        if (game == null) {
            message.append(']').append(ChatColor.GOLD).append(" <inactive>");
        } else {
            if (holder.getMap().getCategories().size() > 1) {
                message.append(ChatColor.GRAY).append("/").append(ChatColor.AQUA).append(toTitleHumanCase(game.getGameMode()));
            }
            message.append(ChatColor.GRAY).append("] ");
            // message.append('(').append(ChatColor.GOLD).append(game.getGameId()).append(ChatColor.GRAY).append(") ");
            EnumSet<GameAddon> addons = game.getAddons();
            if (!addons.isEmpty()) {
                message.append(ChatColor.GRAY).append('(');
                for (GameAddon addon : addons) {
                    message.append(ChatColor.GREEN).append(addon.name());
                    message.append(ChatColor.GRAY).append(',');
                }
                message.setLength(message.length() - 1);
                message.append("] ");
            }
            message.append(ChatColor.GOLD).append(game.getState().getClass().getSimpleName()).append(ChatColor.GRAY).append(" [ ").append(ChatColor.GREEN).append(game.getPlayers().size()).append(ChatColor.GRAY).append("/").append(ChatColor.GREEN).append(game.getMinPlayers()).append(ChatColor.GRAY).append("..").append(ChatColor.GREEN).append(game.getMaxPlayers()).append(ChatColor.GRAY).append("] ");
            OptionalInt timeLeft = WinAfterTimeoutOption.getTimeLeft(game);
            String time = Utils.formatTimeLeft(timeLeft.isPresent() ? timeLeft.getAsInt() : (System.currentTimeMillis() - game.createdAt()) / 1000);
            String word = timeLeft.isPresent() ? " Left" : " Elapsed";
            message.append(time).append(word);
        }
        sender.sendMessage(message.toString());
    }
    return true;
}
Also used : GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Game(com.ebicep.warlords.game.Game) OptionalInt(java.util.OptionalInt) GameAddon(com.ebicep.warlords.game.GameAddon)

Example 4 with GameHolder

use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.

the class SpectateCommand method openSpectateMenu.

public static void openSpectateMenu(Player player) {
    Menu menu = new Menu("Current Games", 9 * 3);
    int column = 0;
    int row = 0;
    for (GameHolder holder : Warlords.getGameManager().getGames()) {
        Game game = holder.getGame();
        if (game != null && game.acceptsSpectators()) {
            menu.setItem(column, row, new ItemBuilder(Material.BOOK).name(ChatColor.GREEN + "Game " + game.getGameId()).lore(ChatColor.DARK_GRAY + "Map - " + ChatColor.RED + game.getMap().getMapName(), ChatColor.DARK_GRAY + "GameMode - " + ChatColor.RED + game.getGameMode(), ChatColor.DARK_GRAY + "Addons - " + ChatColor.RED + game.getAddons(), ChatColor.DARK_GRAY + "Players - " + ChatColor.RED + game.playersCount()).get(), (m, e) -> {
                if (game.isClosed()) {
                    player.sendMessage(ChatColor.RED + "This game is no longer running");
                    openSpectateMenu(player);
                    return;
                }
                if (!game.acceptsSpectators()) {
                    player.sendMessage(ChatColor.RED + "This game does not accepts spectators");
                    openSpectateMenu(player);
                    return;
                }
                Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
                if (currentGame.isPresent() && currentGame.get().getPlayerTeam(player.getUniqueId()) != null) {
                    player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
                } else if (currentGame.isPresent() && currentGame.get().equals(game)) {
                    player.sendMessage(ChatColor.RED + "You are already spectating this game");
                } else {
                    if (currentGame.isPresent()) {
                        currentGame.get().removePlayer(player.getUniqueId());
                    }
                    game.addPlayer(player, true);
                }
            });
            column++;
            if (column > 8) {
                column = 0;
                row++;
            }
        }
    }
    Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
    if (currentGame.isPresent()) {
        menu.setItem(4, 2, new ItemBuilder(Material.BARRIER).name(ChatColor.GREEN + "Return to the lobby").get(), (m, e) -> {
            Optional<Game> currentGame1 = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
            if (currentGame1.isPresent() && currentGame1.get().getPlayerTeam(player.getUniqueId()) != null) {
                player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
            } else {
                currentGame1.get().removePlayer(player.getUniqueId());
            }
        });
    }
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) GameHolder(com.ebicep.warlords.game.GameManager.GameHolder) Game(com.ebicep.warlords.game.Game) Menu(com.ebicep.warlords.menu.Menu)

Example 5 with GameHolder

use of com.ebicep.warlords.game.GameManager.GameHolder 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)

Aggregations

GameHolder (com.ebicep.warlords.game.GameManager.GameHolder)5 Game (com.ebicep.warlords.game.Game)4 PlayingState (com.ebicep.warlords.game.state.PlayingState)2 Warlords (com.ebicep.warlords.Warlords)1 GameAddon (com.ebicep.warlords.game.GameAddon)1 Team (com.ebicep.warlords.game.Team)1 WinAfterTimeoutOption (com.ebicep.warlords.game.option.WinAfterTimeoutOption)1 EndState (com.ebicep.warlords.game.state.EndState)1 PreLobbyState (com.ebicep.warlords.game.state.PreLobbyState)1 Menu (com.ebicep.warlords.menu.Menu)1 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)1 Utils (com.ebicep.warlords.util.warlords.Utils)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 OptionalInt (java.util.OptionalInt)1 LoginException (javax.security.auth.login.LoginException)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 JDA (net.dv8tion.jda.api.JDA)1 JDABuilder (net.dv8tion.jda.api.JDABuilder)1