Help Displaying Player-Specific Info in a Scoreboard

Discussion in 'Plugin Development' started by The Gaming Grunts, Sep 29, 2013.

Thread Status:
Not open for further replies.
  1. Hey everyone! I'm having a problem getting a player's EXP Level and setting that in a scoreboard for only that player. Here is my current code:

    1. public class PlayerInfoBoard
    2. {
    3. public static Scoreboard createPlayerInfoBoard()
    4. {
    5. ScoreboardManager sbmanager = Bukkit.getScoreboardManager();
    6. Scoreboard scoreboard = sbmanager.getNewScoreboard();
    8. Objective expObj = scoreboard.registerNewObjective("PlayerExp", "EXP");
    9. expObj.setDisplaySlot(DisplaySlot.SIDEBAR);
    10. expObj.setDisplayName(ChatColor.GREEN + "Player Info");
    12. Score expScore = expObj.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "Current EXP:"));
    14. for (Player p : Bukkit.getServer().getOnlinePlayers()){
    15. expScore.setScore(p.getLevel());
    16. //for loop doesn't work :(
    17. }
    20. return scoreboard;
    21. }
    22. }

    Then in my onEnable() I have this:

    1. //removed irrelevant code
    2. public class Main extends JavaPlugin implements Listener
    3. {
    4. public PlayerInfoBoard board;
    5. Scoreboard playerInfoBoard;
    7. public void onEnable(){
    8. playerInfoBoard = PlayerInfoBoard.createPlayerInfoBoard();
    9. board = new PlayerInfoBoard();
    10. }

    How would I go about doing this? Thanks :)
  2. I tried playing around with it a bit more, but I still can't figure it out :( The for loop that I have breaks the scoreboard completely and I don't know how else to go about doing this :(
  3. Offline


    Ok so what are you trying to do? Set individual scoreboards?
  4. Yeah that will display player-specific info. In this case it will display the player's EXP level
  5. Offline


  6. Offline


    The Gaming Grunts replace my getLevel() Method with p.getLevel so you will see the Level from the Players LevelBar.

    The Gaming Grunts You could replace the getLevel() Method with everything. You will just need to enter an Integer in there. One possibilty of Integer is like i said the p.getLevel() Method from Bukkit.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page