Search in sources :

Example 1 with WarlordsGameTriggerWinEvent

use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent 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 2 with WarlordsGameTriggerWinEvent

use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent 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)

Example 3 with WarlordsGameTriggerWinEvent

use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent in project Warlords by ebicep.

the class PlayingState method begin.

@Override
@SuppressWarnings("null")
public void begin() {
    this.game.setAcceptsSpectators(true);
    this.game.setAcceptsPlayers(false);
    this.resetTimer();
    RemoveEntities.doRemove(this.game);
    for (Option option : game.getOptions()) {
        option.start(game);
    }
    this.game.forEachOfflinePlayer((player, team) -> {
        if (team != null) {
            PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
            Warlords.addPlayer(new WarlordsPlayer(player, this, team, playerSettings));
        }
    });
    this.game.forEachOfflineWarlordsPlayer(wp -> {
        CustomScoreboard customScoreboard = Warlords.playerScoreboards.get(wp.getUuid());
        updateBasedOnGameState(customScoreboard, wp);
        if (wp.getEntity() instanceof Player) {
            wp.applySkillBoost((Player) wp.getEntity());
        }
    });
    if (DatabaseManager.playerService != null) {
        Warlords.newChain().async(() -> game.forEachOfflinePlayer((player, team) -> {
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
            DatabaseManager.updatePlayerAsync(databasePlayer);
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.SEASON_5, () -> {
            });
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.WEEKLY, () -> {
            });
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.DAILY, () -> {
            });
        })).execute();
    } else {
        System.out.println("ATTENTION - playerService is null");
    }
    game.registerEvents(new Listener() {

        @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
        public void onWin(WarlordsGameTriggerWinEvent event) {
            game.setNextState(new EndState(game, event));
            winEvent = event;
        }
    });
    GameRunnable.create(game, this::updateScoreboard).runTaskTimer(0, 10);
    new GameRunnable(game) {

        @Override
        public void run() {
            counter++;
            timer += GameRunnable.SECOND;
            if (counter >= 60) {
                counter -= 60;
                PlayerFilter.playingGame(game).forEach(wp -> wp.getMinuteStats().advanceMinute());
            }
            PlayerFilter.playingGame(game).forEach(wp -> wp.getSecondStats().advanceSecond());
        }
    }.runTaskTimer(0, GameRunnable.SECOND);
    game.registerGameMarker(TimerSkipAbleMarker.class, (delay) -> {
        counter += delay / GameRunnable.SECOND;
        timer += delay;
    });
    Warlords.getInstance().hideAndUnhidePeople();
}
Also used : DisplaySlot(org.bukkit.scoreboard.DisplaySlot) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) Player(org.bukkit.entity.Player) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Objective(org.bukkit.scoreboard.Objective) Scoreboard(org.bukkit.scoreboard.Scoreboard) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) GameMode(org.bukkit.GameMode) Location(org.bukkit.Location) SpawnLocationMarker(com.ebicep.warlords.game.option.marker.SpawnLocationMarker) RecordGamesCommand(com.ebicep.warlords.commands.debugcommands.RecordGamesCommand) ScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) TimerSkipAbleMarker(com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker) RemoveEntities(com.ebicep.warlords.util.bukkit.RemoveEntities) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LocationMarker(com.ebicep.warlords.game.option.marker.LocationMarker) Listener(org.bukkit.event.Listener) BotManager(com.ebicep.jda.BotManager) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) SRCalculator(com.ebicep.warlords.sr.SRCalculator) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) PlayerSettings(com.ebicep.warlords.player.PlayerSettings) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) List(java.util.List) Stream(java.util.stream.Stream) Game(com.ebicep.warlords.game.Game) ExperienceManager(com.ebicep.warlords.player.ExperienceManager) EventPriority(org.bukkit.event.EventPriority) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ChatColor(org.bukkit.ChatColor) Option(com.ebicep.warlords.game.option.Option) Comparator(java.util.Comparator) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) Listener(org.bukkit.event.Listener) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) EventHandler(org.bukkit.event.EventHandler) PlayerSettings(com.ebicep.warlords.player.PlayerSettings) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) Option(com.ebicep.warlords.game.option.Option) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 4 with WarlordsGameTriggerWinEvent

use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent in project Warlords by ebicep.

the class WinByPointsOption method onEvent.

@EventHandler
public void onEvent(WarlordsPointsChangedEvent event) {
    if (!hasActivated && event.getNewPoints() >= pointLimit) {
        WarlordsGameTriggerWinEvent e = new WarlordsGameTriggerWinEvent(event.getGame(), this, event.getTeam());
        Bukkit.getPluginManager().callEvent(e);
        if (!e.isCancelled()) {
            hasActivated = true;
        }
    }
}
Also used : WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WarlordsGameTriggerWinEvent (com.ebicep.warlords.events.WarlordsGameTriggerWinEvent)4 Team (com.ebicep.warlords.game.Team)3 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)3 EventHandler (org.bukkit.event.EventHandler)2 BotManager (com.ebicep.jda.BotManager)1 Warlords (com.ebicep.warlords.Warlords)1 RecordGamesCommand (com.ebicep.warlords.commands.debugcommands.RecordGamesCommand)1 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)1 DatabaseGameBase (com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase)1 PlayersCollections (com.ebicep.warlords.database.repositories.player.PlayersCollections)1 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)1 Game (com.ebicep.warlords.game.Game)1 GameAddon (com.ebicep.warlords.game.GameAddon)1 Option (com.ebicep.warlords.game.option.Option)1 LobbyLocationMarker (com.ebicep.warlords.game.option.marker.LobbyLocationMarker)1 LocationMarker (com.ebicep.warlords.game.option.marker.LocationMarker)1 SpawnLocationMarker (com.ebicep.warlords.game.option.marker.SpawnLocationMarker)1 TimerSkipAbleMarker (com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker)1 ScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler)1 CustomScoreboard (com.ebicep.warlords.player.CustomScoreboard)1