More Scoreboard Help!

Discussion in 'Plugin Development' started by SeniorQuack, Nov 25, 2013.

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


    Hey there,

    So finally I have been able to get my scoreboards working, but regarding displaying information on the scoreboard, I may need some help! Below is what the scoreboard looks like with the current code:

    And the code:

    1. package me.SeniorQuack.MatrixScoreboard;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import;
    10. import org.bukkit.scoreboard.DisplaySlot;
    11. import org.bukkit.scoreboard.Objective;
    12. import org.bukkit.scoreboard.Score;
    13. import org.bukkit.scoreboard.Scoreboard;
    14. import org.bukkit.scoreboard.ScoreboardManager;
    16. public class Main extends JavaPlugin implements Listener {
    18. Player player;
    20. @Override
    21. public void onEnable() {
    22. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    23. }
    25. public void scoreboard(Player p) {
    26. ScoreboardManager sbm = Bukkit.getServer().getScoreboardManager();
    27. Scoreboard board = sbm.getNewScoreboard();
    28. Objective obj = board.registerNewObjective("test", "dummy");
    30. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    31. obj.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "-=- " + ChatColor.AQUA + "" + ChatColor.BOLD + "MatrixMC!" + ChatColor.GREEN + "" + ChatColor.BOLD + " -=-");
    33. Score space5= obj.getScore((Bukkit.getOfflinePlayer(" ")));
    34. space5.setScore(-1);
    36. Score tokensname = obj.getScore((Bukkit.getOfflinePlayer(ChatColor.YELLOW + "" + ChatColor.BOLD + "Tokens:")));
    37. tokensname.setScore(-2);
    39. Score tokens = obj.getScore((Bukkit.getOfflinePlayer("tokens here")));
    40. tokens.setScore(-3);
    42. Score space1= obj.getScore((Bukkit.getOfflinePlayer(" ")));
    43. space1.setScore(-4);
    45. Score hoopsname = obj.getScore((Bukkit.getOfflinePlayer(ChatColor.RED + "" + ChatColor.BOLD + "Hoops:")));
    46. hoopsname.setScore(-5);
    48. Score hoops = obj.getScore((Bukkit.getOfflinePlayer("hoops here")));
    49. hoops.setScore(-6);
    51. Score space2 = obj.getScore((Bukkit.getOfflinePlayer(" ")));
    52. space2.setScore(-7);
    54. Score rankname = obj.getScore((Bukkit.getOfflinePlayer(ChatColor.GRAY + "" + ChatColor.BOLD + "Rank:")));
    55. rankname.setScore(-8);
    57. Score rank = obj.getScore((Bukkit.getOfflinePlayer("rank here")));
    58. rank.setScore(-9);
    60. Score space3 = obj.getScore((Bukkit.getOfflinePlayer(" ")));
    61. space3.setScore(-10);
    63. Score staffname = obj.getScore((Bukkit.getOfflinePlayer(ChatColor.BLUE + "" + ChatColor.BOLD + "Staff:")));
    64. staffname.setScore(-11);
    66. Score staff = obj.getScore((Bukkit.getOfflinePlayer("staff here")));
    67. staff.setScore(-12);
    69. Score space4 = obj.getScore((Bukkit.getOfflinePlayer(" ")));
    70. space4.setScore(-13);
    72. p.setScoreboard(board);
    73. }
    75. @EventHandler
    76. public void onPlayerJoin(PlayerJoinEvent e) {
    77. Player p = (e.getPlayer());
    79. this.scoreboard(p);
    80. }
    81. }
    82. }

    What I am mainly focusing on right now is the tokens aspect (see above). How would I be able to incorporate the players tokens into the space that says "tokens here"? This will probably have to do with creating a separate scoreboard for each player. How would I do that? If its any help, the way that I get the player balance from a balance checker in another one of my plugins is by using "TokenManager.getBalance(player.getName())", as TokenManager is part of the tokens plugin that is imported into the build path.

    Basically, I want to incorporate the tokens amount (probably using the above code) and have separate scoreboard for each player.

    Any help is much appreciated!

    - Loki :)

    *EDIT* Java code insert unformatted my code :/
  2. Offline


    SeniorQuack, Score tokens = obj.getScore((Bukkit.getOfflinePlayer(TokenManager.getBalance(p.getName()) + "")));
  3. Offline


    You are already creating a scoreboard per player.

    So you can replace
    Bukkit.getOfflinePlayer("hoops here")
    with your thing of the TokenManager:
    one problem comes up if a player has the same amounts in different categoris like tokens and hoops. Then you add a space at the end so they are not equal any more.
  4. Offline


    Regarding the formatting, switch over to using spaces, for some reason, the comment boxes can't parse tabs.
  5. Offline


    spoljo666 Janmm14 xTrollxDudex

    Thanks for that! Quick question. How would I go at updating the scoreboard so whenever the token amount changes, it the amount changes on the scoreboard?

    @spoljo666 @Janmm14 @xTrollxDudex

    Any help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  6. Offline


    Since there is most likely no event being called when someone gets token you need to update it in a scheduler ever so often. Unless there is an event being triggered when someone gains/loosing tokens then you can connect it with that
    SeniorQuack likes this.
  7. Offline


    So make a repeated task to update the scoreboard? If that were to run every tick, would that cause server strain at all??]

    - Loki
  8. Offline


    It would cause server strain. But shouldn't be too much
  9. Offline


    So not enough for there to be any noticeable difference/strain?
  10. Offline


    It's all going to depend on the server itself, if you've got a big dedi, then you probably won't notice it that much, if you've got a 2GB server, then you would most probably notice it a little more.
    but you don't need to make it every second, why not every minute? or 30 seconds? This would reduce the effects of it on your server, but i do understand that you may want it to update as soon as they get the tokens
  11. Offline


    I understand where you are coming from. There are multiple things to consider. I could make a custom event for token amount changing, but it may just be easier using the runnables. It just depends whether I want to put that strain on the server or not, because there could possibly be token changes every second, so if it is updating every tick, then it will be instant updating. Many things to consider....
Thread Status:
Not open for further replies.

Share This Page