I’m trying to create and display a scoreboard. Here’s how I create it:
UserStorageService userStorageService = Sponge.getServiceManager().provide(UserStorageService.class).get();
String teamName = (userStorageService.get(leader).get().getName() + "'s party").substring(0, 16); //team name max 16 chars
team = Team.builder().prefix(Text.of(partyColor.getTextCode(), " ")).name(teamName).build();
team.setNameTagVisibility(Visibilities.ALWAYS);
//team.setColor(partyColor.getTextColor());
Scoreboard scoreboard = Scoreboard.builder().build();
Objective objective = Objective.builder().name("prova").displayName(Text.of("prova")).criterion(Criteria.HEALTH).build();
scoreboard.registerTeam(team);
objective.getOrCreateScore(Text.of("prova")).setScore(0);
scoreboard.addObjective(objective);
scoreboard.updateDisplaySlot(objective, DisplaySlots.SIDEBAR);
and here’s how I assing it to a player:
team.addMember(player.getTeamRepresentation());
player.setScoreboard(scoreboard);
That code compile, doesn’t trigger any error but it doesn’t display the scoreboard. What am I doing wrong?
EDIT: I’m using Sponge API 7.2.0
I remade your code within my own enviroment and tested it. Here is my code. The main differences is that the “Team” has a display name which may effect the teams, however should not effect the sidebar scoreboard. Are you sure that your “player.setScoreboard” is being called?
Player player = (Player)src;
Objective objective = Objective
.builder()
.criterion(Criteria.HEALTH)
.displayName(Text.of("data"))
.name("health")
.build();
objective.getOrCreateScore(Text.of("Health")).setScore(20);
Team team = Team
.builder()
.nameTagVisibility(Visibilities.ALWAYS)
.members(new HashSet<>(Arrays.asList(player.getTeamRepresentation())))
.prefix(Text.of("[Pre]"))
.name("team")
.displayName(Text.builder("team").color(TextColors.AQUA).build())
.build();
Scoreboard board = Scoreboard
.builder()
.teams(Arrays.asList(team))
.objectives(Arrays.asList(objective))
.build();
board.updateDisplaySlot(objective, DisplaySlots.SIDEBAR);
player.setScoreboard(board);
This is my result
1 Like
Thanks for replying.
Yes I’m absolutely sure that the setScoreboard method is called. I will try using your code.
Ok so I managed to get the scoreboard displayed. The new issue is the prefix color not working:
team = Team.builder().prefix(TextSerializers.FORMATTING_CODE.deserialize(partyColor.getCode())).name(leaderName).displayName(Text.of(teamName)).build();
Where partyColor.getCode() returns a color like &c, &4, etc