Solved Setting personal scoreboards not working

Discussion in 'Plugin Development' started by cheeseypotato, Nov 1, 2019.

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


    Soup, I'm making a 'paintball' plugin and trying to display kills and deaths on the sidebar which i have been able to achieve however it only displays one persons stats 'to everyone and not everyone's individual stats. No errors are occurring and I'm wondering if anyone would know why this is happening. Thanks

    Main / Where everything involved in the problem is going on

    package me.billycombo.Main;
    import java.util.HashMap;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    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;
    import me.billycombo.commands.BlueSpawnSet;
    import me.billycombo.commands.RedSpawnSet;
    import me.billycombo.commands.joinTeam;
    public class Main extends JavaPlugin implements Listener {
        private Snowballs event = new Snowballs(this);
        private joinTeam event2 = new joinTeam();
    public void onEnable(){
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
            public void run() {
                for (Player p:Bukkit.getOnlinePlayers()){
    public static HashMap<String, Scoreboard> UsedScoreboard = new HashMap<String, Scoreboard>();
    public static HashMap<String, Score> killsscore = new HashMap<String, Score>();
    public static HashMap<String, Score> deathsscore = new HashMap<String, Score>();
    public static void create(Player p, String BoardName, String BoardDisplayName){
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getMainScoreboard();
    Objective objective = board.registerNewObjective(BoardName, "dummy", "-Stats-");
    Score kills = objective.getScore(ChatColor.GREEN + "Kills:");
    Score deaths = objective.getScore(ChatColor.GREEN + "Deaths:");
    killsscore.put(p.getName(), kills);
    deathsscore.put(p.getName(), deaths);
    UsedScoreboard.put(p.getName(), board);
    public static void kill(Player p, Player p2){
        String pname = p.getName().toLowerCase();
        String pname2 = p2.getName().toLowerCase();
        Score kills = killsscore.get(pname);
        Score deaths = deathsscore.get(pname2);
        kills.setScore(killsscore.get(pname).getScore() + 1); //In this case everytime you Update the Scoreboard hist Money in the Scoreboard will be set to 100. (Replace the 100 with a Method of you to get the Players Money.
        deaths.setScore(deathsscore.get(pname2).getScore() + 1);
    public static void clearKills(Player p){
        String pname = p.getName().toLowerCase();
        Score kills = killsscore.get(pname);
    public void onPlayerJoin(PlayerJoinEvent ev){
        Player p = ev.getPlayer();
        String pname = p.getName().toLowerCase();
        if (!UsedScoreboard.containsKey(p.getName()))
            create(p, pname, ChatColor.BLUE + "-Stats-");
    public static void set(Player p){
    String pname = p.getName().toLowerCase();
  2. Offline


    You have to create multiple scoreboards, one for each player so that their scores aren't the same. When you call the create method you edit the main scoreboard which everyone sees. Use getNewScoreboard

    EDIT: Also remove the scheduler in the onEnable, once a scoreboard is set (onJoin for example) it updates automatically
    cheeseypotato likes this.
  3. Offline


  4. Offline


    yeah that would help
Thread Status:
Not open for further replies.

Share This Page