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);
}
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 + "]");
}
}
}
});
}
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());
}
});
}
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();
}
Aggregations