Search in sources :

Example 1 with Team

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

the class BotListener method onMessageReceived.

@Override
public void onMessageReceived(MessageReceivedEvent event) {
    Member member = event.getMember();
    Message message = event.getMessage();
    if (event.isFromType(ChannelType.PRIVATE)) {
        if (event.getAuthor().isBot()) {
            return;
        }
        try {
            Long key = Long.parseLong(message.getContentRaw());
            if (DiscordCommand.playerLinkKeys.containsValue(key)) {
                UUID uuid = DiscordCommand.playerLinkKeys.getKey(key);
                if (DatabaseManager.playerService == null)
                    return;
                Warlords.newChain().asyncFirst(() -> DatabaseManager.playerService.findByUUID(uuid)).syncLast(databasePlayer -> {
                    Long id = event.getAuthor().getIdLong();
                    databasePlayer.setDiscordID(id);
                    DatabaseManager.updatePlayerAsync(databasePlayer);
                    event.getPrivateChannel().sendMessage("You linked **" + Bukkit.getOfflinePlayer(uuid).getName() + "** to your discord account (" + id + ").").queue();
                    if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
                        Bukkit.getOfflinePlayer(uuid).getPlayer().sendMessage(ChatColor.GREEN + "Your account was linked to the discord account " + event.getAuthor().getAsTag() + " (" + id + ").");
                    }
                    BotManager.sendDebugMessage(new EmbedBuilder().setColor(3066993).setTitle("Player Linked - " + id).setDescription("UUID: " + uuid + "\n" + "IGN: " + databasePlayer.getName() + "\n" + "KEY: " + key).build());
                }).execute();
            }
        } catch (Exception e) {
            System.out.println(message);
            System.out.println("Could not parseLong from direct message");
            e.printStackTrace();
        }
    } else if (event.isFromType(ChannelType.TEXT)) {
        TextChannel textChannel = event.getTextChannel();
        switch(textChannel.getName().toLowerCase()) {
            case "gs-teams":
            case "bot-teams":
                {
                    if (message.getContentRaw().contains(", Balance Cancelled")) {
                        cancelOnGoingBalance();
                    } else if (!message.getEmbeds().isEmpty() && message.getEmbeds().get(0).getFields().size() == 2) {
                        cancelOnGoingBalance();
                        MessageEmbed embed = message.getEmbeds().get(0);
                        List<String> playerNames = new ArrayList<>();
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            if (fieldName != null && fieldValue != null) {
                                String[] players = fieldValue.replace("```", "").replace(" ", "").split("\n");
                                if (fieldName.contains("Blue Team") || fieldName.contains("Red Team")) {
                                    for (String player : players) {
                                        playerNames.add(player.substring(0, player.indexOf('-')));
                                    }
                                }
                            }
                        }
                        onGoingBalance = new BukkitRunnable() {

                            int counter = 0;

                            @Override
                            public void run() {
                                playerNames.forEach(name -> {
                                    Player player = Bukkit.getPlayer(name);
                                    if (player != null) {
                                        Random random = new Random();
                                        PacketUtils.sendTitle(player, ChatColor.GREEN + Utils.specsOrdered[random.nextInt(Utils.specsOrdered.length)], random.nextInt(2) == 0 ? ChatColor.BLUE.toString() + ChatColor.BOLD + "BLUE" : ChatColor.RED.toString() + ChatColor.BOLD + "RED", 0, 5, 0);
                                    }
                                });
                                // auto cancel after 15 seconds
                                if (counter++ > 20 * 15) {
                                    this.cancel();
                                }
                            }
                        }.runTaskTimer(Warlords.getInstance(), 10, 0);
                    }
                    break;
                }
            case "teams":
                {
                    if (!message.getEmbeds().isEmpty() && message.getEmbeds().get(0).getFields().size() == 2) {
                        cancelOnGoingBalance();
                        MessageEmbed embed = message.getEmbeds().get(0);
                        boolean isExperimental = embed.getTitle().contains("*");
                        List<String> blueTeam = new ArrayList<>();
                        List<String> redTeam = new ArrayList<>();
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            String[] players;
                            if (fieldName != null && fieldValue != null) {
                                players = fieldValue.replace("```", "").split("\n");
                                if (fieldName.contains("Blue Team")) {
                                    blueTeam.add(ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Blue Team" + ChatColor.DARK_GRAY + " - ");
                                    for (String player : players) {
                                        String name = player.substring(0, player.indexOf('-'));
                                        String spec = player.substring(player.indexOf('-') + 1);
                                        blueTeam.add(ChatColor.BLUE + name + ChatColor.GRAY + " - " + ChatColor.YELLOW + spec);
                                    }
                                } else if (fieldName.contains("Red Team")) {
                                    redTeam.add(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "Red Team" + ChatColor.DARK_GRAY + " - ");
                                    for (String player : players) {
                                        String name = player.substring(0, player.indexOf('-'));
                                        String spec = player.substring(player.indexOf('-') + 1);
                                        redTeam.add(ChatColor.RED + name + ChatColor.GRAY + " - " + ChatColor.YELLOW + spec);
                                    }
                                }
                            }
                        }
                        AtomicBoolean resetMenu = new AtomicBoolean(true);
                        for (MessageEmbed.Field field : embed.getFields()) {
                            String fieldName = field.getName();
                            String fieldValue = field.getValue();
                            String[] players;
                            if (fieldName != null && fieldValue != null) {
                                boolean isBlueTeam = fieldName.contains("Blue Team");
                                boolean isRedTeam = fieldName.contains("Red Team");
                                players = fieldValue.replace("```", "").replace(" ", "").split("\n");
                                try {
                                    Bukkit.getScheduler().callSyncMethod(Warlords.getInstance(), () -> {
                                        for (String player : players) {
                                            String name = player.substring(0, player.indexOf('-'));
                                            String spec = player.substring(player.indexOf('-') + 1);
                                            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
                                            if (offlinePlayer == null)
                                                continue;
                                            UUID uuid = offlinePlayer.getUniqueId();
                                            if (resetMenu.get()) {
                                                Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> party.getRegularGamesMenu().reset());
                                                resetMenu.set(false);
                                            }
                                            // includes offline players
                                            if (isBlueTeam) {
                                                Warlords.getPlayerSettings(uuid).setWantedTeam(Team.BLUE);
                                            } else if (isRedTeam) {
                                                Warlords.getPlayerSettings(uuid).setWantedTeam(Team.RED);
                                            }
                                            if (!spec.isEmpty()) {
                                                Warlords.getPlayerSettings(uuid).setSelectedClass(Classes.getClass(spec));
                                                DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(uuid);
                                                databasePlayer.setLastSpec(Classes.getClass(spec));
                                                DatabaseManager.updatePlayerAsync(databasePlayer);
                                            // TODO: fix
                                            /*if (!isExperimental) {
                                                    Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                        party.getRegularGamesMenu().getRegularGamePlayers().add(
                                                                new RegularGamesMenu.RegularGamePlayer(uuid, isBlueTeam ? Team.BLUE : Team.RED, Classes.getClass(spec))
                                                        );
                                                    });
                                                }*/
                                            } else {
                                            // TODO: fix
                                            /*if (!isExperimental) {
                                                    Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                        party.getRegularGamesMenu().getRegularGamePlayers().add(
                                                                new RegularGamesMenu.RegularGamePlayer(uuid, isBlueTeam ? Team.BLUE : Team.RED, Classes.PYROMANCER)
                                                        );
                                                    });
                                                }*/
                                            }
                                            if (!isExperimental) {
                                                Warlords.partyManager.getPartyFromAny(uuid).ifPresent(party -> {
                                                    if (offlinePlayer.isOnline()) {
                                                        offlinePlayer.getPlayer().getInventory().setItem(7, new ItemBuilder((isBlueTeam ? Team.BLUE : Team.RED).getItem()).name("§aTeam Builder").get());
                                                    }
                                                });
                                            }
                                            // only send messages to online
                                            if (offlinePlayer.isOnline()) {
                                                Player targetPlayer = offlinePlayer.getPlayer();
                                                targetPlayer.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
                                                if (isBlueTeam) {
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "You were automatically put into the " + ChatColor.BLUE + "BLUE" + ChatColor.GREEN + " team!");
                                                } else if (isRedTeam) {
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "You were automatically put into the " + ChatColor.RED + "RED" + ChatColor.GREEN + " team!");
                                                }
                                                if (!spec.isEmpty()) {
                                                    PacketUtils.sendTitle(targetPlayer, ChatColor.GREEN + spec, isBlueTeam ? ChatColor.BLUE.toString() + ChatColor.BOLD + "BLUE" : isRedTeam ? ChatColor.RED.toString() + ChatColor.BOLD + "RED" : "", 0, 100, 40);
                                                    targetPlayer.sendMessage(ChatColor.GREEN + "Your spec was automatically changed to " + ChatColor.YELLOW + spec + ChatColor.GREEN + "!");
                                                }
                                                targetPlayer.sendMessage("");
                                                blueTeam.forEach(s -> {
                                                    if (s.contains(name)) {
                                                        targetPlayer.sendMessage(ChatColor.GREEN + s.substring(2, s.indexOf('-') - 2) + s.substring(s.indexOf('-') - 2));
                                                    } else {
                                                        targetPlayer.sendMessage(s);
                                                    }
                                                });
                                                redTeam.forEach(s -> {
                                                    if (s.contains(name)) {
                                                        targetPlayer.sendMessage(ChatColor.GREEN + s.substring(2, s.indexOf('-') - 2) + s.substring(s.indexOf('-') - 2));
                                                    } else {
                                                        targetPlayer.sendMessage(s);
                                                    }
                                                });
                                                targetPlayer.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
                                            }
                                        }
                                        return null;
                                    }).get();
                                } catch (InterruptedException | ExecutionException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                    break;
                }
            case "waiting":
                {
                    if (member != null && member.getUser().isBot()) {
                        return;
                    }
                    // disable queue on test servers
                    if (!Warlords.serverIP.equals("51.81.49.127")) {
                        return;
                    }
                    String queueCommand = message.getContentRaw();
                    String[] args = queueCommand.substring(1).split(" ");
                    // System.out.println(Arrays.toString(args));
                    if (member != null) {
                        String playerName = member.getEffectiveName();
                        if (queueCommand.equalsIgnoreCase("-queue")) {
                            QueueManager.sendNewQueue();
                        } else if (queueCommand.startsWith("-queue") && args.length > 0) {
                            switch(args[1]) {
                                case "join":
                                    {
                                        if (QueueManager.queue.stream().anyMatch(uuid -> uuid.equals(Bukkit.getOfflinePlayer(playerName).getUniqueId())) || QueueManager.futureQueue.stream().anyMatch(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            message.reply("You are already in the queue!").queue();
                                            break;
                                        }
                                        if (args.length == 3) {
                                            // adding to queue for future time
                                            try {
                                                String futureTime = args[2];
                                                SimpleDateFormat hourFormat = new SimpleDateFormat("hh");
                                                SimpleDateFormat minuteFormat = new SimpleDateFormat("mm");
                                                hourFormat.setTimeZone(TimeZone.getTimeZone("EST"));
                                                minuteFormat.setTimeZone(TimeZone.getTimeZone("EST"));
                                                Date date = new Date();
                                                int currentHour = Integer.parseInt(hourFormat.format(date));
                                                int currentMinute = Integer.parseInt(minuteFormat.format(date));
                                                int hourDiff = Integer.parseInt(futureTime.substring(0, futureTime.indexOf(':'))) - currentHour;
                                                int minuteDiff = Integer.parseInt(futureTime.substring(futureTime.indexOf(':') + 1)) - currentMinute;
                                                if (hourDiff > 5) {
                                                    textChannel.sendMessage("You cannot join the queue 3+ hours ahead").queue();
                                                } else if (hourDiff == 0 && minuteDiff < 20) {
                                                    textChannel.sendMessage("You cannot join the queue within 20 minutes. Join the server and type **/queue join** to join the queue now").queue();
                                                } else if (hourDiff >= 0) {
                                                    long futureTimeMillis = System.currentTimeMillis();
                                                    futureTimeMillis += hourDiff * 3600000L;
                                                    futureTimeMillis += minuteDiff * 60000L;
                                                    long diff = futureTimeMillis - System.currentTimeMillis();
                                                    message.reply("You will join the queue in **" + TimeUnit.MILLISECONDS.toMinutes(diff) + "** minutes. Make sure you are online at that time or you will be automatically removed if there is an open party spot!").queue();
                                                    QueueManager.addPlayerToFutureQueue(playerName, futureTime, new BukkitRunnable() {

                                                        @Override
                                                        public void run() {
                                                            QueueManager.addPlayerToQueue(playerName, false);
                                                            QueueManager.futureQueue.removeIf(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(member.getEffectiveName()).getUniqueId()));
                                                            textChannel.sendMessage("<@" + member.getId() + "> You are now in the queue, make sure you are on the server once the party is open").queue();
                                                            QueueManager.sendNewQueue();
                                                        }
                                                    }.runTaskLater(Warlords.getInstance(), TimeUnit.MILLISECONDS.toSeconds(diff) * 20));
                                                } else {
                                                    message.reply("Invalid Time - HOUR:MINUTE").queue();
                                                }
                                            } catch (Exception e) {
                                                message.reply("Invalid Time - HOUR:MINUTE").queue();
                                            }
                                        } else {
                                            // adding to queue normally
                                            QueueManager.addPlayerToQueue(member.getEffectiveName(), false);
                                        }
                                        break;
                                    }
                                case "leave":
                                    {
                                        if (QueueManager.queue.stream().anyMatch(uuid -> uuid.equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            QueueManager.removePlayerFromQueue(playerName);
                                            message.reply("You left the queue!").queue();
                                            break;
                                        } else if (QueueManager.futureQueue.stream().anyMatch(futureQueuePlayer -> futureQueuePlayer.getUuid().equals(Bukkit.getOfflinePlayer(playerName).getUniqueId()))) {
                                            QueueManager.removePlayerFromFutureQueue(playerName);
                                            message.reply("You left the future queue!").queue();
                                            break;
                                        }
                                        break;
                                    }
                            }
                            QueueManager.sendNewQueue();
                            break;
                        }
                    }
                }
        }
    }
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscordCommand(com.ebicep.warlords.commands.miscellaneouscommands.DiscordCommand) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) EventHandler(org.bukkit.event.EventHandler) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Classes(com.ebicep.warlords.player.Classes) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Team(com.ebicep.warlords.game.Team) QueueManager(com.ebicep.warlords.queuesystem.QueueManager) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) Warlords(com.ebicep.warlords.Warlords) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) OfflinePlayer(org.bukkit.OfflinePlayer) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) BukkitTask(org.bukkit.scheduler.BukkitTask) ChatColor(org.bukkit.ChatColor) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) OfflinePlayer(org.bukkit.OfflinePlayer) ExecutionException(java.util.concurrent.ExecutionException) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) OfflinePlayer(org.bukkit.OfflinePlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Team

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

the class GameOvertimeOption method onEvent.

@EventHandler(ignoreCancelled = true)
public void onEvent(WarlordsGameTriggerWinEvent event) {
    if (!wasActivated && event.getCause() instanceof WinAfterTimeoutOption && event.getDeclaredWinner() == null) {
        event.setCancelled(true);
        for (Team team : TeamMarker.getTeams(event.getGame())) {
            event.getGame().setPoints(team, 0);
        }
        for (Option option : event.getGame().getOptions()) {
            if (option instanceof WinByPointsOption) {
                WinByPointsOption winByPointsOption = (WinByPointsOption) option;
                winByPointsOption.setPointLimit(overTimePoints);
            }
        }
        WinAfterTimeoutOption drawAfterTimeoutOption = (WinAfterTimeoutOption) event.getCause();
        drawAfterTimeoutOption.setTimeRemaining(overTimeTime);
        event.getGame().forEachOnlinePlayerWithoutSpectators((player, team) -> {
            PacketUtils.sendTitle(player, ChatColor.LIGHT_PURPLE + "OVERTIME!", ChatColor.YELLOW + "First team to reach " + overTimePoints + " points wins!", 0, 60, 0);
            player.sendMessage("§dOvertime is now active!");
            player.playSound(player.getLocation(), Sound.PORTAL_TRAVEL, 1, 1);
        });
        wasActivated = true;
    }
}
Also used : Team(com.ebicep.warlords.game.Team) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Team

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

the class ImposterModeOption method sendPoll.

public void sendPoll(Team team) {
    poll = new GamePoll.Builder(game).setQuestion("Who is the most SUS on your team?").setTimeLeft(60).setOptions(game.offlinePlayersWithoutSpectators().filter(uuidTeamEntry -> uuidTeamEntry.getValue() == team).map(offlinePlayerTeamEntry -> offlinePlayerTeamEntry.getKey().getName()).collect(Collectors.toList())).setExcludedPlayers(game.offlinePlayersWithoutSpectators().filter(uuidTeamEntry -> uuidTeamEntry.getValue() != team).map(offlinePlayerTeamEntry -> offlinePlayerTeamEntry.getKey().getUniqueId()).collect(Collectors.toList())).setRunnableAfterPollEnded(p -> {
        int mostVotes = Collections.max(p.getOptionsWithVotes().entrySet(), Comparator.comparingInt(Map.Entry::getValue)).getValue();
        List<WarlordsPlayer> votedOut = p.getOptionsWithVotes().entrySet().stream().filter(stringIntegerEntry -> stringIntegerEntry.getValue() == mostVotes).map(Map.Entry::getKey).map(s -> game.warlordsPlayers().filter(warlordsPlayer -> warlordsPlayer.getName().equals(s)).findFirst().get()).collect(Collectors.toList());
        // If multiple top votes and one is imposter then voted wrong
        boolean votedCorrectly = votedOut.size() == 1 && imposters.get(team).stream().anyMatch(warlordsPlayer -> warlordsPlayer == votedOut.get(0));
        new GameRunnable(game, true) {

            int counter = 0;

            @Override
            public void run() {
                String title = "";
                String subtitle = "";
                switch(counter) {
                    case 0:
                    case 1:
                        title = team.teamColor + team.name + " voted...";
                        break;
                    case 2:
                    case 3:
                        if (votedCorrectly) {
                            title = ChatColor.GREEN + "Correctly!";
                        } else {
                            title = ChatColor.RED + "Incorrectly!";
                        }
                        subtitle = team.teamColor + imposters.get(team).get(0).getName() + ChatColor.YELLOW + " was the imposter";
                        break;
                }
                counter++;
                if (counter < 6) {
                    sendTitle(title, subtitle);
                } else if (counter == 6) {
                    game.onlinePlayersWithoutSpectators().forEach(playerTeamEntry -> {
                        Player player = playerTeamEntry.getKey();
                        player.removePotionEffect(PotionEffectType.BLINDNESS);
                        showWinLossMessage(team, player, votedCorrectly, playerTeamEntry.getValue() == team);
                    });
                } else if (counter == 9) {
                    game.removeFrozenCause(team.teamColor + team.name + ChatColor.GREEN + " is voting!");
                    int scoreNeededToEndGame = game.getOptions().stream().filter(e -> e instanceof WinByPointsOption).mapToInt(e -> ((WinByPointsOption) e).getPointLimit()).sorted().findFirst().orElse(Integer.MAX_VALUE);
                    if (votedCorrectly) {
                        game.setPoints(team, scoreNeededToEndGame);
                    } else {
                        // team with most points win, excluding voting team
                        game.setPoints(TeamMarker.getTeams(game).stream().filter(t -> t != team).min(Comparator.comparingInt(o -> game.getPoints(o))).get(), scoreNeededToEndGame);
                    }
                    ((PlayingState) game.getState()).skipTimer();
                    game.onlinePlayers().forEach(playerTeamEntry -> {
                        Player player = playerTeamEntry.getKey();
                        sendImpostorResult(player);
                    });
                    this.cancel();
                }
            }
        }.runTaskTimer(10, 20);
    }).get();
}
Also used : java.util(java.util) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) Team(com.ebicep.warlords.game.Team) PlayingState(com.ebicep.warlords.game.state.PlayingState) GamePoll(com.ebicep.warlords.poll.polls.GamePoll) Warlords(com.ebicep.warlords.Warlords) Player(org.bukkit.entity.Player) ChatUtils(com.ebicep.warlords.util.chat.ChatUtils) Collectors(java.util.stream.Collectors) SimpleScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler) Game(com.ebicep.warlords.game.Game) ScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ChatColor(org.bukkit.ChatColor) TeamMarker(com.ebicep.warlords.game.option.marker.TeamMarker) Nonnull(javax.annotation.Nonnull) PotionEffectType(org.bukkit.potion.PotionEffectType) Nullable(javax.annotation.Nullable) Player(org.bukkit.entity.Player) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GamePoll(com.ebicep.warlords.poll.polls.GamePoll) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable)

Example 4 with Team

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

the class MercyWinOption method start.

@Override
public void start(Game game) {
    EnumSet<Team> teams = TeamMarker.getTeams(game);
    new GameRunnable(game) {

        @Override
        public void run() {
            if (timer > 0) {
                timer--;
                return;
            }
            int higest = Integer.MIN_VALUE;
            int secondHighest = Integer.MIN_VALUE;
            Team winner = null;
            for (Team team : teams) {
                int points = game.getPoints(team);
                if (points > higest) {
                    winner = team;
                    secondHighest = higest;
                    higest = points;
                } else if (points > secondHighest) {
                    secondHighest = points;
                }
            }
            if (higest - limit >= secondHighest) {
                WarlordsGameTriggerWinEvent event = new WarlordsGameTriggerWinEvent(game, MercyWinOption.this, winner);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    cancel();
                }
            }
        }
    }.runTaskTimer(1 * SECOND, 1 * SECOND);
}
Also used : GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) Team(com.ebicep.warlords.game.Team)

Example 5 with Team

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

the class WinAfterTimeoutOption method start.

@Override
public void start(Game game) {
    this.runTaskTimer = new GameRunnable(game) {

        @Override
        public void run() {
            timeRemaining--;
            if (timeRemaining <= 0) {
                Team leader;
                if (winner == null) {
                    int higest = Integer.MIN_VALUE;
                    int secondHighest = Integer.MIN_VALUE;
                    leader = null;
                    for (Team team : TeamMarker.getTeams(game)) {
                        int points = game.getPoints(team);
                        if (points > higest) {
                            leader = team;
                            secondHighest = higest;
                            higest = points;
                        } else if (points > secondHighest) {
                            secondHighest = points;
                        }
                    }
                    if (higest <= secondHighest) {
                        leader = null;
                    }
                } else {
                    leader = winner;
                }
                WarlordsGameTriggerWinEvent event = new WarlordsGameTriggerWinEvent(game, WinAfterTimeoutOption.this, leader);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    cancel();
                }
            }
            scoreboard.markChanged();
        }
    }.runTaskTimer(1 * SECOND, 1 * SECOND);
}
Also used : GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) Team(com.ebicep.warlords.game.Team)

Aggregations

Team (com.ebicep.warlords.game.Team)27 Warlords (com.ebicep.warlords.Warlords)14 Player (org.bukkit.entity.Player)14 Game (com.ebicep.warlords.game.Game)13 Collectors (java.util.stream.Collectors)11 ChatColor (org.bukkit.ChatColor)11 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)10 java.util (java.util)9 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)8 Nonnull (javax.annotation.Nonnull)8 Nullable (javax.annotation.Nullable)8 ScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler)7 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)7 ItemStack (org.bukkit.inventory.ItemStack)7 LobbyLocationMarker (com.ebicep.warlords.game.option.marker.LobbyLocationMarker)6 TeamMarker (com.ebicep.warlords.game.option.marker.TeamMarker)6 SimpleScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler)6 PacketUtils (com.ebicep.warlords.util.bukkit.PacketUtils)6 Utils (com.ebicep.warlords.util.warlords.Utils)6 List (java.util.List)6