Creating per-player scoreboard and using teams

Hi,
I’ve been having a hard time finding a solution for my issue, I want players to have an unique scoreboard, with their respective stats, which I’ve been able to do by just creating different scoreboards and put them in a Map to link them to the players.

The problem is that I also want players to see and have prefixes, it can be done by creating Teams, but then I would need to use a single scoreboard for everyone to see the prefixes, which I don’t want.

I’ve been able to change the name in chat and in the tablist manually to show the prefix I want, but I haven’t been able to change the nameplate over the player head, is there anyway to do that ? Or is there a way to have unique scoreboards per player and use teams at the same time that I didn’t thought about ?

Thanks in advance!

The name above the head is (i believe) attached to the skin in 1.12. So you wont be able to change the name without changing the skin.

As for teams with a separate scoreboard, I have never used teams before so i could be completely wrong but arnt teams added to an objective? If so couldnt you just add it to the “above head” display slot and have some information there about the player (such as health? Score? Etc?)

Hi, first of all sorry my late reply and thank you for your answer!

Oh really ? What about the older versions then ? 1.11 or 1.10 ?

I’m not sure you quite got what I want to do, this is what I am trying to achieve:

Screenshot

As you can see there is a personal scoreboard on the sidebar and the player is in a team which I can see because I set the scoreboard to myself like this:

Code

@Listener
public void onEnable(GameInitializationEvent e){
sb = Scoreboard.builder().build();
blue = Team.builder().name(“Blue”).build();
blue.setColor(TextColors.DARK_BLUE);
blue.setPrefix(Text.of(TextColors.DARK_BLUE));
blue.setCanSeeFriendlyInvisibles(true);
blue.setAllowFriendlyFire(true);
sb.registerTeam(blue);
}

@Listener
public void onJoin(ClientConnectionEvent.Join e){
	
    Player p = e.getTargetEntity();
	blue.addMember(p.getTeamRepresentation());
	p.setScoreboard(sb);
	
}

For the sidebar scoreboard I obviously need to create a scoreboard for each player, because I can’t put different objectives on the sidebar at the same time, which is exactly my problem :confused:

Ill do some testing. As for older versions such as 1.11 or 1.10, they are also the same. Its 1.13+ that maybe different. I have seen a lot of plugins for bukkit that state they are “name changers” after 1.13 came out for bukkit.

I got a way for it to work, its a bit … strange.

It works by essentially creating a team on a per player bases, making it so player names appear with all the modifications yet the scoreboard is a per person bases. Here is my code.

Main
private static final TeamUpdater BLUE = new TeamUpdater(Team.builder().
        name("Blue").
        color(TextColors.DARK_BLUE).
        prefix(Text.builder("[Test] ").color(TextColors.BLUE).build()).
        build());
private static final TeamUpdater RED = new TeamUpdater(Team.builder().
        name("Red").
        color(TextColors.DARK_RED).
        prefix(Text.builder("[Test] ").color(TextColors.RED).build()).
        build());

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event){
    Scoreboard scoreboard = Scoreboard.builder().build();
    Objective objective = Objective.builder().criterion(Criteria.DUMMY).name(event.getTargetEntity().getName() + "Test").displayName(Text.of("test")).build();
    Score score = objective.getOrCreateScore(Text.builder("Kills").build());
    score.setScore(new Random().nextInt(100));
    scoreboard.addObjective(objective);
    scoreboard.updateDisplaySlot(objective, DisplaySlots.SIDEBAR);
    event.getTargetEntity().setScoreboard(scoreboard);
    BLUE.addMember(event.getTargetEntity());
}
TeamUpdater
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.scoreboard.Team;
import org.spongepowered.api.text.Text;

public class TeamUpdater {

    private Team basedOn;

    public TeamUpdater(Team team){
        this.basedOn = team;
    }

    public Team getBasedOn(){
        return this.basedOn;
    }

    public void update(){
        Sponge.getServer().getOnlinePlayers().stream().filter(p -> p.getScoreboard().getTeam(this.basedOn.getName() + p.getName()).isPresent()).forEach(p -> {
            p.getScoreboard().getTeam(this.basedOn.getName() + p.getName()).get().unregister();
            p.getScoreboard().registerTeam(buildTeam(p));
        });
    }

    private Team buildTeam(Player player){
        Team team = Team.builder().from(this.basedOn).name(this.basedOn.getName() + player.getName()).build();
        return team;
    }

    public void addMember(Player player){
        this.basedOn.addMember(player.getTeamRepresentation());
        player.getScoreboard().registerTeam(buildTeam(player));
        update();
    }
}

Thanks for this!

It seems to have a problem tho, it basically only works when I add players to the same team, that’s what happens when I try adding two different players to two different teams:

Screen n°1

Or there is this bug that happened like twice where the player sees the other in the same team as he is but he actually isn’t:

Screen n°2

Whats the code your using? There shouldn’t be a bug in the sponge implementation. So it maybe a issue on your end