Search in sources :

Example 1 with PreLobbyState

use of com.ebicep.warlords.game.state.PreLobbyState 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 PreLobbyState

use of com.ebicep.warlords.game.state.PreLobbyState in project Warlords by ebicep.

the class WarlordsEvents method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    Action action = e.getAction();
    Location location = player.getLocation();
    WarlordsPlayer wp = Warlords.getPlayer(player);
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
        ItemStack itemHeld = player.getItemInHand();
        if (wp != null && wp.isAlive() && !wp.getGame().isFrozen()) {
            if (player.getInventory().getHeldItemSlot() == 7 && itemHeld.getType() == Material.GOLD_BARDING && player.getVehicle() == null && wp.getHorseCooldown() <= 0) {
                if (!Utils.isMountableZone(location) || Utils.blocksInFrontOfLocation(location)) {
                    player.sendMessage(ChatColor.RED + "You can't mount here!");
                } else {
                    double distance = player.getLocation().getY() - player.getWorld().getHighestBlockYAt(player.getLocation());
                    if (distance > 2) {
                        player.sendMessage(ChatColor.RED + "You can't mount in the air!");
                    } else if (wp.getCarriedFlag() != null) {
                        player.sendMessage(ChatColor.RED + "You can't mount while holding the flag!");
                    } else {
                        player.playSound(player.getLocation(), "mountup", 1, 1);
                        wp.getHorse().spawn();
                        wp.setHorseCooldown(wp.getHorse().getCooldown());
                    }
                }
            } else if (itemHeld.getType() == Material.BONE) {
                player.getInventory().remove(UndyingArmy.BONE);
                wp.addDamageInstance(Warlords.getPlayer(player), "", 100000, 100000, -1, 100, false);
            } else if (itemHeld.getType() == Material.BANNER) {
                if (wp.getFlagCooldown() > 0) {
                    player.sendMessage("§cYou cannot drop the flag yet, please wait 5 seconds!");
                } else if (wp.getCooldownManager().hasCooldown(TimeWarp.class)) {
                    player.sendMessage(ChatColor.RED + "You cannot drop the flag with a Time Warp active!");
                } else {
                    FlagHolder.dropFlagForPlayer(wp);
                    wp.setFlagCooldown(5);
                }
            } else if (itemHeld.getType() == Material.COMPASS) {
                player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 2);
                wp.toggleTeamFlagCompass();
            } else if (player.getInventory().getHeldItemSlot() == 0 || !Warlords.getPlayerSettings(wp.getUuid()).getHotKeyMode()) {
                wp.getSpec().onRightClick(wp, player);
            }
        } else {
            PreLobbyState state = Warlords.getGameManager().getPlayerGame(player.getUniqueId()).flatMap(g -> g.getState(PreLobbyState.class)).orElse(null);
            if (state != null) {
                state.interactEvent(player, player.getInventory().getHeldItemSlot());
            } else if (itemHeld.getType() == Material.NETHER_STAR) {
                // menu
                openMainMenu(player);
            } else if (itemHeld.getType() == Material.EMERALD) {
                // wl command
                Bukkit.getServer().dispatchCommand(player, "wl");
            } else if (itemHeld.getType() == Material.BLAZE_POWDER) {
                openMapsMenu(player);
            } else if (itemHeld.getType() == Material.WOOL) {
                if (itemHeld.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Team Builder")) {
                    Warlords.partyManager.getPartyFromAny(player.getUniqueId()).ifPresent(party -> {
                        List<RegularGamesMenu.RegularGamePlayer> playerList = party.getRegularGamesMenu().getRegularGamePlayers();
                        if (!playerList.isEmpty()) {
                            party.getRegularGamesMenu().openMenuForPlayer(player);
                            new BukkitRunnable() {

                                @Override
                                public void run() {
                                    if (player.getOpenInventory().getTopInventory().getName().equals("Team Builder")) {
                                        party.getRegularGamesMenu().openMenuForPlayer(player);
                                    } else {
                                        this.cancel();
                                    }
                                }
                            }.runTaskTimer(Warlords.getInstance(), 20, 10);
                        }
                    });
                }
            }
        }
    } else if (action == Action.LEFT_CLICK_BLOCK || action == Action.LEFT_CLICK_AIR) {
        if (action == Action.LEFT_CLICK_AIR) {
        }
    }
}
Also used : PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) GameManager(com.ebicep.warlords.game.GameManager) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) GameMenu.openMainMenu(com.ebicep.warlords.menu.GameMenu.openMainMenu) org.bukkit(org.bukkit) EventHandler(org.bukkit.event.EventHandler) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) PreLobbyState(com.ebicep.warlords.game.state.PreLobbyState) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) org.bukkit.entity(org.bukkit.entity) BlockPhysicsEvent(org.bukkit.event.block.BlockPhysicsEvent) org.bukkit.event.player(org.bukkit.event.player) PermissionHandler(com.ebicep.warlords.permissions.PermissionHandler) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Warlords(com.ebicep.warlords.Warlords) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) ItemStack(org.bukkit.inventory.ItemStack) InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) PotionEffectType(org.bukkit.potion.PotionEffectType) Utils(com.ebicep.warlords.util.warlords.Utils) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) java.util(java.util) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) org.bukkit.event.entity(org.bukkit.event.entity) ChatUtils(com.ebicep.warlords.util.chat.ChatUtils) Action(org.bukkit.event.block.Action) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) Level(java.util.logging.Level) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) Listener(org.bukkit.event.Listener) WaitingFlagLocation(com.ebicep.warlords.game.flags.WaitingFlagLocation) org.bukkit.craftbukkit.v1_8_R3.inventory(org.bukkit.craftbukkit.v1_8_R3.inventory) InventoryType(org.bukkit.event.inventory.InventoryType) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) RegularGamesMenu(com.ebicep.warlords.party.RegularGamesMenu) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) DebugMenuGameOptions.openMapsMenu(com.ebicep.warlords.menu.debugmenu.DebugMenuGameOptions.openMapsMenu) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) com.ebicep.warlords.player(com.ebicep.warlords.player) ExecutionException(java.util.concurrent.ExecutionException) ChatChannels(com.ebicep.warlords.util.chat.ChatChannels) EventPriority(org.bukkit.event.EventPriority) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation) EndState(com.ebicep.warlords.game.state.EndState) Action(org.bukkit.event.block.Action) PreLobbyState(com.ebicep.warlords.game.state.PreLobbyState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) WaitingFlagLocation(com.ebicep.warlords.game.flags.WaitingFlagLocation) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Warlords (com.ebicep.warlords.Warlords)2 PreLobbyState (com.ebicep.warlords.game.state.PreLobbyState)2 Utils (com.ebicep.warlords.util.warlords.Utils)2 java.util (java.util)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 com.ebicep.warlords.abilties (com.ebicep.warlords.abilties)1 AbstractPlayerClass (com.ebicep.warlords.classes.AbstractPlayerClass)1 Spiritguard (com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard)1 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)1 LeaderboardManager (com.ebicep.warlords.database.leaderboards.LeaderboardManager)1 DatabaseGameBase (com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase)1 PlayersCollections (com.ebicep.warlords.database.repositories.player.PlayersCollections)1 Game (com.ebicep.warlords.game.Game)1 GameManager (com.ebicep.warlords.game.GameManager)1 GameHolder (com.ebicep.warlords.game.GameManager.GameHolder)1 Team (com.ebicep.warlords.game.Team)1 GroundFlagLocation (com.ebicep.warlords.game.flags.GroundFlagLocation)1 PlayerFlagLocation (com.ebicep.warlords.game.flags.PlayerFlagLocation)1 SpawnFlagLocation (com.ebicep.warlords.game.flags.SpawnFlagLocation)1 WaitingFlagLocation (com.ebicep.warlords.game.flags.WaitingFlagLocation)1