Search in sources :

Example 21 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class GameFreezeWhenOfflineOption method start.

@Override
public void start(Game game) {
    new GameRunnable(game, true) {

        @Override
        public void run() {
            boolean anyOffline = game.offlinePlayersWithoutSpectators().anyMatch(e -> !e.getKey().isOnline());
            if (isFrozen) {
                if (anyOffline) {
                    timer = 0;
                } else if (timer >= UNFREEZE_TIME) {
                    game.removeFrozenCause(FROZEN_MESSAGE);
                    isFrozen = false;
                    timer = 0;
                } else {
                    game.forEachOnlinePlayerWithoutSpectators((p, team) -> {
                        PacketUtils.sendTitle(p, ChatColor.BLUE + "Resuming in... " + ChatColor.GREEN + (UNFREEZE_TIME - timer), "", 0, 40, 0);
                    });
                    timer++;
                }
            } else {
                if (!anyOffline) {
                    timer = 0;
                } else if (timer >= FREEZE_TIME) {
                    game.addFrozenCause(FROZEN_MESSAGE);
                    isFrozen = true;
                    timer = 0;
                } else {
                    timer++;
                }
            }
        }
    }.runTaskTimer(0, 20);
}
Also used : GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Game(com.ebicep.warlords.game.Game) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) ChatColor(org.bukkit.ChatColor) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable)

Example 22 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable 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 23 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class InterceptionPointOption method start.

@Override
public void start(Game game) {
    Location clone = this.location.clone();
    clone.add(0, -1.7, 0);
    for (int i = middle.length - 1; i >= 0; i--) {
        clone.add(0, this.captureProgress * 1 + 0.25, 0);
        middle[i] = location.getWorld().spawn(clone, ArmorStand.class);
        middle[i].setGravity(false);
        middle[i].setBasePlate(false);
        middle[i].setArms(false);
        middle[i].setVisible(false);
    }
    updateArmorstandsAndEffect(null);
    scoreboard.registerChangeHandler(this::updateArmorstandsAndEffect);
    new GameRunnable(game) {

        @Override
        public void run() {
            Stream<WarlordsPlayer> computePlayers = computePlayers();
            double speed = updateTeamInCircle(computePlayers);
            updateTeamHackProcess(speed);
            if (effectPlayer != null) {
                effectPlayer.playEffects();
            }
        }
    }.runTaskTimer(1, 1);
}
Also used : ArmorStand(org.bukkit.entity.ArmorStand) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Stream(java.util.stream.Stream) Location(org.bukkit.Location)

Example 24 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable 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 25 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable 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

GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)53 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)39 Location (org.bukkit.Location)34 Player (org.bukkit.entity.Player)23 Utils (com.ebicep.warlords.util.warlords.Utils)21 CooldownTypes (com.ebicep.warlords.player.cooldowns.CooldownTypes)17 AbstractAbility (com.ebicep.warlords.classes.AbstractAbility)16 ParticleEffect (com.ebicep.warlords.effects.ParticleEffect)16 RegularCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown)16 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)16 WarlordsDamageHealingEvent (com.ebicep.warlords.events.WarlordsDamageHealingEvent)13 ItemStack (org.bukkit.inventory.ItemStack)13 ArmorStand (org.bukkit.entity.ArmorStand)12 Vector (org.bukkit.util.Vector)11 ChatColor (org.bukkit.ChatColor)10 Material (org.bukkit.Material)10 Warlords (com.ebicep.warlords.Warlords)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Nonnull (javax.annotation.Nonnull)9