1.16.x Custom Scoreboard Team Prefixes

Discussion in 'Spigot Plugin Development' started by Qhucy, Sep 16, 2020 at 1:16 PM.

  1. Hello!

    I have a plugin that displays a custom scoreboard for each player since the information on the board will depend on what player is seeing the board.

    What I am trying to do is change the prefix and suffix of the nametag above a given player's head for everyone. However, players must be on the same team to see the prefix and suffix nametag above another team member's head.

    Since every player has a different scoreboard (and thus different teams) it doesn't really seem possible for every player to see the prefix and suffix above every other player's head.

    I have found one way to solve this but it seems terribly inefficient and I would like to know if there is an easier way of doing so.

    What I am doing now is (for each individual player scoreboard), I am adding every other online player on the server to each player's scoreboard team. This way, every player on the server will be on the same team and will be able to see the prefix and suffix.

    This all works fine, but this seems like a really inefficient way to do this. If there are 10 players online on the server, there will be 10 different teams, with each 1 team having those 10 players on it, creating an exponential amount of instances every following player.

    Is there a way to make it so Team's aren't attached to a scoreboard? The only way I can find to even create an instance of a team is from the Scoreboard.java class. If there isn't a way to make team's independent of scoreboards, is there a more efficient way to achieve what I am trying to do?

    Any help is appreciated, thanks!
     
  2. There is no better way within the spigot API. Every player has their own scoreboard and these teams "in" that scoreboard determine the strings displayed over the heads of others. You could also manipulate packets if you really want to.
    I had the exact same issue a while ago and while the project is not finished yet, I haven't really noticed any lag caused by that.
     
  3. It's not lag as much as it is memory because if you do the math and you have 100 players online you end up having to create 100 different teams for each player to show every else's prefix uniquely. 100 x 100 = 10,000 Teams in total which takes up a ton of memory. The total teams over players graph is exponential as well.

    I guess it's just unfortunate that there's no other better way to do it though, I thought I might as well ask.
     
  4. In theory you're right, we have θ(n^2) memory, but the type of what we store matters too. A team shouldn't be that much internally I think.