How to automatically update the sidebar

I put the sidebar with the following code.

Code
@Listener
public void onEntity(ClientConnectionEvent.Join e) {
    Player p = e.getTargetEntity();
    Scoreboard sb = Scoreboard.builder().build();
    Objective obj = Objective.builder().criterion(Criteria.DUMMY).displayName(Text.of("§c۞ §b§lSky§4§lTech §c۞")).name("MainSideBoard").build();
    
    Score s1 = obj.getOrCreateScore(Text.of("§0-----------------", ""));
    s1.setScore(7);
    Score s2 = obj.getOrCreateScore(Text.of("§3Ваш ник: §f", p.getName()));
    s2.setScore(6);
    Score s3 = obj.getOrCreateScore(Text.of("§0-----------------", " "));
    s3.setScore(5);
    Score s4 = obj.getOrCreateScore(Text.of("§2Ваш баланс: §6", getPlayerBalance(p)));
    s4.setScore(4);
    Score s5 = obj.getOrCreateScore(Text.of("§0-----------------", "  "));
    s5.setScore(3);
    Score s6 = obj.getOrCreateScore(Text.of("§bОнлайн: §9", Sponge.getServer().getOnlinePlayers().size(), "§7/§9", Sponge.getServer().getMaxPlayers()));
    s6.setScore(2);
    Score s7 = obj.getOrCreateScore(Text.of("§0-----------------", "   "));
    s7.setScore(1);

    sb.addObjective(obj);
    sb.updateDisplaySlot(obj, DisplaySlots.SIDEBAR);
    p.setScoreboard(sb);
}

I need to set up automatic updates Player values balance and online on server in real time.

Because there is no event for balance update that part would be difficult to update in real time. You could listen to a event that is always going on such as EntityMoveEvent and then update everyones scoreboard from that. Or you could setup a scheduler that runs every 5ticks that updates everyones scoreboard.

As for updating the online players. I would use the event you currently have and run the code you currently have but I would update every online players scoreboard not just the player who joins.

Sponge.getServer().getOnlinePlayers();

That will get a collection of online players. After that use either

stream().foreach(p ->

Or

for(Player player : players) {

To loop through each player.

I was able to do the required function with the help of the scheduler. Thank you.

If use the scheduler, the server memory overflow occurs. I even did clear Scoreboard before updating it, but it did not help.

 public void setScoreboard (Player p) {
    Task.Builder taskBuilder = Task.builder();
	taskBuilder.execute(() -> {
	p.getScoreboard().getScores().clear();
	Scoreboard sb = Scoreboard.builder().build();
	Objective obj = Objective.builder().criterion(Criteria.DUMMY).displayName(Text.of("§c۞ §b§lSky§4§lTech §c۞")).name("MainSideBoard").build();
	Score s1 = obj.getOrCreateScore(Text.of("§0-----------------", ""));
	    s1.setScore(7);
	    Score s2 = obj.getOrCreateScore(Text.of("§6Ваш ник: §f", p.getName()));
	    s2.setScore(6);
	    Score s3 = obj.getOrCreateScore(Text.of("§0-----------------", " "));
	    s3.setScore(5);
	    Score s4 = obj.getOrCreateScore(Text.of("§6Ваш баланс: §2$", getPlayerBalance(p)));
	    s4.setScore(4);
	    Score s5 = obj.getOrCreateScore(Text.of("§0-----------------", "  "));
	    s5.setScore(3);
	    Score s6 = obj.getOrCreateScore(Text.of("§6Онлайн: §9", Sponge.getServer().getOnlinePlayers().size(), "§7/§9", Sponge.getServer().getMaxPlayers()));
	    s6.setScore(2);
	    Score s7 = obj.getOrCreateScore(Text.of("§0-----------------", "   "));
	    s7.setScore(1);
	    sb.addObjective(obj);
	    sb.updateDisplaySlot(obj, DisplaySlots.SIDEBAR);
	    p.setScoreboard(sb);
	})
	.interval(2, TimeUnit.SECONDS)
	.submit(this);
}