Scoreboard Kills & Health

Discussion in 'Spigot Plugin Development' started by DidactCraft, May 28, 2015.

  1. Ok, can anyone help me out with this. I'm trying to create a scoreboard which returns the amount of kills a player has, how much health, and the tps of the server. Please if you can help me out it would be greatly appreciate!

    Code so far:
    public void Scoreboard() {
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test1", "test2");
    objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&c&lDidact &c&lKit&f&lPvP"));
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);


    for(Player online : Bukkit.getOnlinePlayers()){
    online.setScoreboard(board);
    }


    Player p = Bukkit.getServer().getPlayer(getName());

    Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f&l")));
    score.setScore(15);
    Score score1 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f&l&nStats")));
    score1.setScore(14);
    Score score2 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&cHealth:&f")));
    score2.setScore(13);


    }

    Thanks in advance
     
  2. So what's the problem? Where do you get stuck, do you have any issues? If you don't tell us the issue we can't really help you...
     
  3. As I stated above, there is no issue. But how do I return the amount of health the player has and the amount of kills they have. And how do I implement that into the scoreboard*
     
  4. First one has a getter method: Player#getHealth(). The second one is one you might want to track for yourself, or use Statistic.PLAYER_KILLS
    Create a score for it.
     
  5. Here is my new code:

    public void Scoreboard() {
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test1", "test2");
    objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&c&lDidact &c&lKit&f&lPvP"));
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);


    for(Player online : Bukkit.getOnlinePlayers()){
    online.setScoreboard(board);
    }


    Player p = Bukkit.getServer().getPlayer(getName());

    Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f&l")));
    score.setScore(15);
    Score score1 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f&l&nStats")));
    score1.setScore(14);
    Score score2 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&c&l")));
    score2.setScore(13);
    Score score3 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&c&lHealth")));
    score3.setScore(12);
    Score score4 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f" + p.getHealth())));
    score4.setScore(11);
    Score score5 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&c&lKills")));
    score5.setScore(10);
    Score score6 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', "&f" + p.getStatistic(PLAYER_KILLS))));
    score6.setScore(9);


    }
    The p.getHealth is ambigous for the type player, and the PLAYER_KILLS isnt a thing.
     
    #6 DidactCraft, May 28, 2015
    Last edited: May 28, 2015
  6. YOU DONT HAVE TO READ MY POST:




    If you want to you can get rid of 1 line of code by doing:

    You have:
    Code (Text):
    board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test1", "test2");
    Revised:
    Code (Text):
    Objective objective = manager.getNewScoreboard().registerNewObjective("test1", "test2");
    And then:
    Code (Text):
    online.setScoreboard(manager.getNewScoreboard());
    Correct me if I'm wrong, this is how my friend and I did it.
     
  7. Depend on the Spigot API, not the Spigot server. Also, my link proves that it does exist, you just don't seem to know how to use enums.
     
  8. Thanks, but it really doesn't change anything :D
     
  9. What do you mean by ambiguous? I think you'll want to compare Player#getHealth to Player#getMaxHealth() (Correct me if I'm wrong). As for the statistic:
    Code (Text):
    p.getStatistic(Statistic.PLAYER_KILLS)
    should work.
     
  10. I'm new to coding, not very good with enums and all :(
     
  11. Then I'd suggest reading up on them and how to use them - it'll be very useful later on ;)
     
  12. Can someone actually help me rather than telling me to go look up on it. This is a plugin development help topic not a go and look for a solution topic
     
  13. Yes they are helping you by directing you to what you are looking for, many people on the forums don't believe in feeding people with code as they never actually learn and just copy and paste.
     
  14. I'm not looking to copy and paste. I have a photographic memory, and I can use that to my advantage.
     
  15. By that logic you could look at everything in the Spigot API and become a professional developer, happy readings. https://hub.spigotmc.org/javadocs/spigot/
     
  16. We should be able to assume that you know how to use basic Java and OO development (it's kind of a requirement of plugin development).

    If you don't fully grasp (some of the aspects of) Java, it's probably wiser to link to resources that are better at explaining how stuff works than scrambling something together which might not always be 100% correct or complete. The majority of this can also be found using google, hence the 'look it up' :p.

    We don't intend to not help you, we just tend to help you in a way which is beneficial for you as well (googling stuff is generally faster for basic questions, which means you find your answers faster - plus stack overflow probably has the majority of basic questions answered beautifully).

    For comparison, I could either write a full tutorial on how to use enums, or just link you the Oracle documentation which probably answers everything you ever want to know about enums for the next few years :).
     
  17. Ok I've been researching and have come up with this so far:
    http://pastebin.com/qNdnRjUt
    It comes up with a error saying NPE
     
  18. Can you post the stack trace as well?