Help with scoreboard!

Discussion in 'Plugin Development' started by RainoBoy97, Jun 15, 2013.

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

    RainoBoy97

    Hello Bukkit community! :)

    I need some help with a scoreboard for kills. I wan't each player to see their own kills. This is what I got so far, the scoreboard is showing up for each player, but not updating as I wan't :c
    Show Spoiler

    Code:
    package me.rainoboy97.GIPvP;
     
    import static org.bukkit.ChatColor.BOLD;
    import static org.bukkit.ChatColor.GOLD;
    import static org.bukkit.ChatColor.GREEN;
     
    import java.util.HashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
     
    public class ScoreboardUtil {
     
    @SuppressWarnings("unused")
    private GIPvP plugin;
    private static KillHandler killHandler;
     
    public static HashMap<String, Scoreboard> scoreboards = new HashMap<String, Scoreboard>();
     
    @SuppressWarnings("static-access")
    public ScoreboardUtil(GIPvP plugin) {
    this.plugin = plugin;
    this.killHandler = new KillHandler(plugin);
    }
     
    public static void scoreboard(Player player) {
    String name = player.getName();
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("sideKills", "dummy");
    Score score = objective.getScore(Bukkit.getOfflinePlayer(GREEN + "Kills:"));
    score.setScore(killHandler.getKills(player));
     
    if (scoreboards.containsKey(name)) {
    Scoreboard scoreboard = scoreboards.get(name);
    player.setScoreboard(scoreboard);
    return;
    }
     
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName(GOLD + BOLD.toString() + "Your statistics:");
    player.setScoreboard(board);
    scoreboards.put(player.getName(), board);
    }
     
    public static void addKill(Player player) {
    String name = player.getName();
    Scoreboard scoreboard = scoreboards.get(name);
    Score score = scoreboard.getObjective("sideKills").getScore(Bukkit.getOfflinePlayer(GREEN + "Kills:"));
    score.setScore(killHandler.getKills(player));
    scoreboards.put(name, scoreboard);
    player.setScoreboard(scoreboards.get(name));
    }
     
    }
    


    I would appreciate any help :)
     
  2. Offline

    Minnymin3

  3. Offline

    RainoBoy97

    I wan't it to be per player, so I can display the statistics for the players.
     
  4. Offline

    GreySwordz

    I haven't tested this, but I'm pretty sure this:
    Code:
    Objective objective = board.registerNewObjective("sideKills", "dummy");
    should be this:
    Code:
    Objective objective = board.registerNewObjective("sideKills", kills);
    or this:
    Code:
    Objective objective = board.registerNewObjective("sideKills", kill);
     
  5. Offline

    RainoBoy97

    No.
     
  6. Offline

    GreySwordz

    Ah, found it. It's playerKillCount, as found here
     
  7. Offline

    chasechocolate

    RainoBoy97 do you want each player to see their own statistics? I may post a class that I use to save statistics in the resources section soon.
     
  8. Offline

    RainoBoy97

    Yes, I want each player to see their kills, and not everyone else's. Thanks :)

    No, that's not what I want. I want it per player, so each player see's their kills and not everyone elses.

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

    GreySwordz

    RainoBoy97 It should have it per player. Did you test it?
     
Thread Status:
Not open for further replies.

Share This Page