Scoreboards

Discussion in 'Plugin Development' started by GalaxyCraft, Aug 17, 2014.

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

    GalaxyCraft

    Hello Everyone,
    I am creating a scoreboard plugin.
    I need the plugin to be compatible with PrisonRankup.

    I have no idea where to start, i have googled several times how to create a scoreboard but no tutorials helped :(

    If you could give me the code, or not, but explain in detail (Im a beginner) on how to create a scoreboard.

    Thanks in advanced

    Unique
     
  2. Offline

    stormneo7

    Don't copy and paste. You won't learn.
    You can read my explaination or read chasechocolate's.
    https://forums.bukkit.org/threads/tutorial-scoreboards-teams-with-the-bukkit-api.139655/

    Code:java
    1. final Player p = Bukkit.getPlayer("stormneo7");
    2. // Firstly we need to get a scoreboard. We could obviously use p.getScoreboard() but I'm just going to create a new one.
    3. final Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    4. // Next we'll register a new objective, what the scoreboard is designed to do. We don't want it to do anything special so we'll name it something random like 'random' and 'scrub'.
    5. final Objective obj = scoreboard.registerNewObjective("random", "scrub");
    6. // We'll set the DisplayName of the board to "Your Stats".
    7. obj.setDisplayName("Your Stats"); // This could be colored as you desire.
    8. // Set where the scoreboard goes. In this case, the sidebar.
    9. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    10.  
    11. // Now the scoring part. Remember, scores must be an Integer (I believe has to be above or equal to 0).
    12. // We'll create a score in the scoreboard named "PlayersOnline" and set it's score to the online players.
    13. final Score Online = obj.getScore(Bukkit.getOfflinePlayer("PlayersOnline")); // This too can be colored as you wish.
    14. Online.setScore(Bukkit.getOnlinePlayers().length);
    15.  
    16. // Sets the player's scoreboard.
    17. p.setScoreboard(scoreboard);
    18.  
    19. // You can create as many scores as you like but I believe 16 is the limit.
    20. // Please also note that scores are listed from the highest to the least.
     
Thread Status:
Not open for further replies.

Share This Page