Different scoreboards per player (and teams)

Discussion in 'Plugin Development' started by Scizzr, Aug 19, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    So I've got the gist of scoreboards down:
    1. get the manager
    2. make a new scoreboard
    3. add objective with name and dummy
    4. add fake player names to the objective as scores to see custom values
    5. set the player(s) to use this board

    What I can't figure out is how to have each player have their own list of things. For example, I am working on something that allows for multiple teams (from a config file) and each team will have a list of objectives that will need to be completed to win (collect X, kill X, etc). I have made a single scoreboard with multiple teams but what happens is when one team kills something, all teams see the changes. Okay, that's expected. Where I am having trouble is when I try to make more than one scoreboard. What I'm getting is the scoreboards flickering back and forth with each other (whoever updates the scoreboard last is the scoreboard that everyone sees). My scoreboards look like this (for example):

    -- Red Scoreboard --        -- Blue Scoreboard--
    §cKill 10 pigs:   10        §cKill 10 pigs:   10
    §1Kill 10 pigs:    4        §1Kill 10 pigs:    4
    When Blue kills a pig, red team members end up seeing blue's scoreboard. I'm thinking it's something to do with the way I am making the scoreboards (I make one initially, boardDefault, and then change it to make one for red and one for blue). I guess what I need to do is make completely new scoreboards from scratch, and setup the teams for each scoreboard. The issue with that would be the fact that each scoreboard would have its own team. Do multiple scoreboards and the same team names count as one team? For example, a scoreboard for Red and a scoreboard for Blue and since they're two different objects, I have to add teams for red and for blue to each. That makes:

    Blue scoreboard
    - Red team
    - Blue team
    Red scoreboard
    - Red team
    - Blue team

    Do both red teams and both blue teams count as the same? (for anti-teamkill, see invis teammates, etc) it seems like they wouldn't (since they're literally two different Team objects). If not, how can I achieve what I am looking for? (different scoreboards for each team, ability to have teams and switch teams as needed)

    Any advice would be much appreciated. :)
  2. Offline

    Wolvereness Bukkit Team Member

    All scoreboards are independently isolated, exception of the default objectives that get incremented automagically. No change to one scoreboard affects any other scoreboard. It's also worth noting scoreboards are kept by reference; if you edit a scoreboard, all places you use that particular scoreboard are also modified. More reading on that particular concept can be found here or more specifically, here.

    When you're actually creating a team, you'll notice that you cannot pass a team to a scoreboard; you need to have the scoreboard create one for you. The resulting team is only applicable for that particular scoreboard it was created from, similarly to variables in objects that are passed by reference (as noted in the above links).
  3. Offline


    I understand the kept by reference concept, but thanks for the reference material. :)

    But basically, is there any way to have two scoreboards and two teams? Or do I have to just do lots of checks to cancel damage if the team that both players are on is the same name? That's the only way I can think of doing it... That or making a HashMap<String, String> and keeping the player's names and their team name (Red, Blue, etc) and checking against that.

    Thanks for the reply.
Thread Status:
Not open for further replies.

Share This Page