Search in sources :

Example 1 with CustomScoreboard

use of com.ebicep.warlords.player.CustomScoreboard in project Warlords by ebicep.

the class PlayingState method onPlayerReJoinGame.

@Override
public void onPlayerReJoinGame(@Nonnull Player player) {
    WarlordsPlayer wp = Warlords.getPlayer(player);
    if (wp == null) {
        // Spectator
        player.setGameMode(GameMode.SPECTATOR);
        Location spawn = Stream.concat(getGame().getMarkers(SpawnLocationMarker.class).stream(), getGame().getMarkers(LobbyLocationMarker.class).stream()).map(LocationMarker::getLocation).collect(Utils.randomElement());
        player.teleport(spawn);
    }
    CustomScoreboard sb = Warlords.playerScoreboards.get(player.getUniqueId());
    updateBasedOnGameState(sb, wp);
}
Also used : WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) Location(org.bukkit.Location)

Example 2 with CustomScoreboard

use of com.ebicep.warlords.player.CustomScoreboard in project Warlords by ebicep.

the class PlayingState method updateNames.

private void updateNames(@Nonnull CustomScoreboard customScoreboard) {
    Scoreboard scoreboard = customScoreboard.getScoreboard();
    this.getGame().forEachOfflinePlayer((player, team) -> {
        WarlordsPlayer warlordsPlayer = Warlords.getPlayer(player);
        if (warlordsPlayer != null) {
            if (scoreboard.getTeam(warlordsPlayer.getName()) == null) {
                org.bukkit.scoreboard.Team temp = scoreboard.registerNewTeam(warlordsPlayer.getName());
                temp.setPrefix(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + warlordsPlayer.getSpec().getClassNameShort() + ChatColor.DARK_GRAY + "] " + team.teamColor());
                temp.addEntry(warlordsPlayer.getName());
                temp.setSuffix(ChatColor.DARK_GRAY + " [" + ChatColor.GOLD + "Lv" + ExperienceManager.getLevelString(ExperienceManager.getLevelForSpec(warlordsPlayer.getUuid(), warlordsPlayer.getSpecClass())) + ChatColor.DARK_GRAY + "]");
            } else {
                scoreboard.getTeam(warlordsPlayer.getName()).setPrefix(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + warlordsPlayer.getSpec().getClassNameShort() + ChatColor.DARK_GRAY + "] " + team.teamColor());
                if (warlordsPlayer.getCarriedFlag() != null) {
                    scoreboard.getTeam(warlordsPlayer.getName()).setSuffix(ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + "Lv" + ExperienceManager.getLevelString(ExperienceManager.getLevelForSpec(warlordsPlayer.getUuid(), warlordsPlayer.getSpecClass())) + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + "⚑");
                } else {
                    scoreboard.getTeam(warlordsPlayer.getName()).setSuffix(ChatColor.DARK_GRAY + " [" + ChatColor.GRAY + "Lv" + ExperienceManager.getLevelString(ExperienceManager.getLevelForSpec(warlordsPlayer.getUuid(), warlordsPlayer.getSpecClass())) + ChatColor.DARK_GRAY + "]");
                }
            }
        }
    });
}
Also used : WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) Scoreboard(org.bukkit.scoreboard.Scoreboard)

Example 3 with CustomScoreboard

use of com.ebicep.warlords.player.CustomScoreboard in project Warlords by ebicep.

the class PlayingState method updateHealth.

private void updateHealth(@Nonnull CustomScoreboard customScoreboard) {
    Scoreboard scoreboard = customScoreboard.getScoreboard();
    Objective health = customScoreboard.getHealth();
    if (health == null || scoreboard.getObjective("health") == null) {
        health = scoreboard.registerNewObjective("health", "dummy");
        health.setDisplaySlot(DisplaySlot.BELOW_NAME);
        health.setDisplayName(ChatColor.RED + "❤");
        customScoreboard.setHealth(health);
    }
    Objective finalHealth = health;
    this.getGame().forEachOfflinePlayer((player, team) -> {
        WarlordsPlayer warlordsPlayer = Warlords.getPlayer(player);
        if (warlordsPlayer != null) {
            finalHealth.getScore(warlordsPlayer.getName()).setScore(warlordsPlayer.getHealth());
        }
    });
}
Also used : Objective(org.bukkit.scoreboard.Objective) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) Scoreboard(org.bukkit.scoreboard.Scoreboard)

Example 4 with CustomScoreboard

use of com.ebicep.warlords.player.CustomScoreboard 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)

Aggregations

CustomScoreboard (com.ebicep.warlords.player.CustomScoreboard)4 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)4 Scoreboard (org.bukkit.scoreboard.Scoreboard)3 Location (org.bukkit.Location)2 Objective (org.bukkit.scoreboard.Objective)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 WarlordsGameTriggerWinEvent (com.ebicep.warlords.events.WarlordsGameTriggerWinEvent)1 Game (com.ebicep.warlords.game.Game)1 GameAddon (com.ebicep.warlords.game.GameAddon)1 Team (com.ebicep.warlords.game.Team)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