Multiple scoreboards at the same time

Discussion in 'Plugin Development' started by Tomass, Apr 19, 2014.

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

    Tomass

    Hello,

    How can I use the scoreboard below name and the sidebar scoreboard at the same time? I tried to find information in "Resources" forum, but found nothing...

    Thank you!
     
  2. Offline

    TheMcScavenger

  3. Offline

    TopTobster5

    You have to say where you want it to display using 'objective.setDisplaySlot(DisplaySlot.SIDEBAR);
     
  4. Offline

    Tomass

    TheMcScavenger and TopTobster5
    Yes I known that, but one scoreboard replace another... Now I try this:
    Code:java
    1. public static void Scoreb(Player p) {
    2. ScoreboardManager manager = Bukkit.getScoreboardManager();
    3. Scoreboard board = manager.getNewScoreboard();
    4. Objective objective = board.registerNewObjective("GAME", "playerKillCount");
    5.  
    6. objective.setDisplayName(ChatColor.YELLOW + "Leaders:");
    7. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    8. p.setScoreboard(objective.getScoreboard());
    9. }
    10. public static void scoreKills() {
    11. ScoreboardManager manager = Bukkit.getScoreboardManager();
    12. Scoreboard board = manager.getNewScoreboard();
    13. Objective objective = board.registerNewObjective("GAME-Kills", "dummy");
    14.  
    15. objective.setDisplayName(ChatColor.RED +" Kills");
    16. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    17. for (Player online : Bukkit.getOnlinePlayers()) {
    18. if (Main.kills.get(online.getName()) == null) {
    19. Main.kills.put(online.getName(), 0);
    20. } else {
    21. Score score = objective.getScore(online);
    22. score.setScore(Main.kills.get(online.getName()));
    23. }
    24.  
    25. }
    26. for (Player online : Bukkit.getOnlinePlayers()) {
    27. online.setScoreboard(board);
    28.  
    29. }
    30.  
    31. }


    Scoreb scoreboard I set, then player join the game.
    scoreKills scoreboard I refresh, at the PlayerDeathEvent.

    Thanks :)
     
  5. Offline

    TopTobster5

    Tomass You need to call them different things, I.E. have 'ScoreboardManager manager1' and then 'ScoreboardManager manager2' etc.
     
  6. Offline

    Tomass

    Ohh, I think I known, there is problem.. I need to create a global variables with scoreboardmanager
     
  7. Offline

    coasterman10

    Global variables are not a good idea for this. In fact, unless you can provide a very specific reason global variables will work and instance variables will not work, you should not use them at all.

    While you're at it, you should abolish any usage of static since nothing here calls for static objects or methods. All that does is break encapsulation. While it won't affect how the end product runs very much, it may be easier to work with now, but later down the line when you have to make changes, this will become a mess. Maintainability is one of, if not the, highest priority of writing code.

    That being said, you should create one scoreboard, two objectives on that scoreboard, and set their display slots accordingly.
     
    Tomass likes this.
  8. Offline

    Mysticate

    This guy knows what's up
     
  9. Offline

    Tomass

    I did as you said and it worked. Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page