Scoreboard not updating

Discussion in 'Plugin Development' started by nolemretaW, Apr 16, 2021.

  1. Offline

    nolemretaW

    Why updateScoreboard doesn't work? createScoreboard works since I can see the scoreboard after executing createScoreboard
    Code:
    package pl.lightblock.engine.managers;
    
    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.ScoreboardManager;
    
    public class Scoreboard {
        public void createScoreboard(Player p){
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard();
            Objective obj = board.registerNewObjective("Score", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("§eLIGHT§fBLOCK§e.PL");
    
            Score score1 = obj.getScore("§8§eLIGHT§fBLOCK§e.PL");
            score1.setScore(1);
    
            Score score2 = obj.getScore(" ");
            score2.setScore(2);
    
            Score score3 = obj.getScore("§7Jesteś połączony z trybem: §eSkyBlock");
            score3.setScore(3);
    
            Score score4 = obj.getScore("§7Twój nick: §e" + p.getDisplayName());
            score4.setScore(4);
    
            Score score5 = obj.getScore("§7Gracze online: §e" + Bukkit.getOnlinePlayers().size());
            score5.setScore(5);
    
            Score score6 = obj.getScore(" ");
            score6.setScore(6);
    
            Score score7 = obj.getScore("§8§eLIGHT§fBLOCK§e.PL");
            score7.setScore(7);
    
            p.setScoreboard(board);
        }
        public void updateScoreboard(){
            for(Player players : Bukkit.getOnlinePlayers()){
                createScoreboard(players);
            }
        }
    }
     
  2. Offline

    Newdel

    What does that mean "doesn't work"
    Does it refuse to update or to just show at all?
    If it doesn't show: When you do want it to show? OnCommand? OnJoin? etc
    If it doesn't update: Try to get the old scoreboard of a player (Player#getScoreboard()) and try to update this.
    The code itself looks fine to me. Maybe "Bukkit.getOnlinePlayers()" is too long for a line in a scoreboard? Don't know exactly
     

Share This Page