Scoreboard Task Minecraft Bug. It Flashes

Discussion in 'Spigot Plugin Development' started by Nosmakos, May 23, 2016.

  1. hey guys i made a scoreboard with a task to onEnable to load the scoreboard every 20 seconds for the players who are online but the thing is that if i go to the game some times the scoreboard is doing flashes like the title of scoreboard goes in the position where a score is and turns back to where it was and this is happening in 0.1 second that's why i call it flash its happening really fast any idea why this is happening?
    the scoreboard looks like this:
    Code (Text):
        public void setupScoreboard(Player player){
            if (this.getConfig().getBoolean("Scoreboard.Enable") == true){
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard board = manager.getNewScoreboard();
                Objective o = board.registerNewObjective("Scoreboard", "dummy");
                o.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Scoreboard.TitleName")));
                Score one = o.getScore(ChatColor.STRIKETHROUGH + " ------------------"); <= EXAMPLE
    and in the onEnable:
    Code (Text):
            BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
            Scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
            }, 0, 20L);
    #1 Nosmakos, May 23, 2016
    Last edited: May 23, 2016
  2. anyone? i think it's minecraft bug but i can't solve it.
  3. You are running it every 20 ticks, not seconds
    When you setup the scoreboards, it will flash, that's just how minecraft works. if you change the 20 ticks to 400 ticks, it will only flash once every 20 seconds
  4. 20 ticks = 1 second

    @Nosma_Stew YOu should use teams instead of Score. You are resetting the full scoreboard every second, so it removes the scoreboard and it sets the scoreboard. Use teams for no flicker.
  5. hmmm yes but it will change the changes if someone kill?
  6. why ? :(
  7. Using teams has no flicker as you only update the teams. Look at the attachment I added. A little example to use teams.

    Attached Files:

  8. Here's a Scoreboard class that I use, and I don't think
    it flashes, if I remember correctly.

    This is not my code, so use it as you wish,
    but don't take credit for it.

    Code (Text):
    import java.util.AbstractMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;
    public class SimpleScoreboard {
        private Scoreboard scoreboard;
        private String title;
        private Map<String, Integer> scores;
        private List<Team> teams;
        public SimpleScoreboard(String title) {
            this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            this.title = title;
            this.scores = Maps.newLinkedHashMap();
            this.teams = Lists.newArrayList();
        public void blankLine() {
        public void add(String text) {
            add(text, null);
        public void add(String text, Integer score) {
            Preconditions.checkArgument(text.length() < 48, "text cannot be over 48 characters in length");
            text = fixDuplicates(text);
            scores.put(text, score);
        private String fixDuplicates(String text) {
            while (scores.containsKey(text))
                text += "§r";
            if (text.length() > 48)
                text = text.substring(0, 47);
            return text;
        private Map.Entry<Team, String> createTeam(String text) {
            String result = "";
            if (text.length() <= 16)
                return new AbstractMap.SimpleEntry<>(null, text);
            Team team = scoreboard.registerNewTeam("text-" + scoreboard.getTeams().size());
            Iterator<String> iterator = Splitter.fixedLength(16).split(text).iterator();
            result =;
            if (text.length() > 32)
            return new AbstractMap.SimpleEntry<>(team, result);
        public void build() {
            Objective obj = scoreboard.registerNewObjective((title.length() > 16 ? title.substring(0, 15) : title), "dummy");
            int index = scores.size();
            for (Map.Entry<String, Integer> text : scores.entrySet()) {
                Map.Entry<Team, String> team = createTeam(text.getKey());
                Integer score = text.getValue() != null ? text.getValue() : index;
                //Modification start
                final Map.Entry<Team, String> teamf = team;
                OfflinePlayer player = new OfflinePlayer() {
                    public void setOp(boolean arg0) { }
                    public void setWhitelisted(boolean arg0) {}
                    public void setBanned(boolean arg0) {}
                    public Map<String, Object> serialize() {
                        return null;
                    public boolean isOp() {
                        return false;
                    public boolean isWhitelisted() {
                        return false;
                    public boolean isOnline() {
                        return false;
                    public boolean isBanned() {
                        return false;
                    public boolean hasPlayedBefore() {
                        return false;
                    public UUID getUniqueId() {
                        return null;
                    public Player getPlayer() {
                        return null;
                    public String getName() {
                        return teamf.getValue();
                    public long getLastPlayed() {
                        return 0;
                    public long getFirstPlayed() {
                        return 0;
                    public Location getBedSpawnLocation() {
                        return null;
                //Modification end
                if (team.getKey() != null)
                index -= 1;
        public void reset() {
            title = null;
            for (Team t : teams)
        public Scoreboard getScoreboard() {
            return scoreboard;
        public void send(Player... players) {
            for (Player p : players)
    • Like Like x 1
  9. 400 ticks = 20 seconds. So he should use 400 ticks.
  10. The timing has nothing to do with.

    If there is a way to update the scores rather
    that re-creating the entire scoreboard will
    ease the flashing.
  11. If he changes the delay to 400 ticks, the scoreboard will only flash once every 20 seconds. You have provided a better solution, but mine was definitely not wrong as I am telling him how to make what he initially intended to make.
  12. it will update it in every change or after 20 seconds? and the flashes it happends it's not every 1 seconds but whenever it wants for example it flashes now and after 10 seconds it does it again or 20 or 5 its weird.
    thanks for this i will take a look thought but i won't use it i just want to check where my problem is because i checked if it prevents lag but it doesnt so i think its a bug because someone said he has a fix for this but its a minecraft bug.
  13. Better solution is to use teams.

    @Nosma_Stew You should use teams. I provided a document where I explain it. Read it ;)
  14. so you don't need any task with the teams am i correct?
  15. Only if you want to update it for all players you simply make a BukkitRunnable, loop through all player's and use the updateScoreBoard(player); method. Pm me if you need any help.
  16. okay thanks for that! im checking what i can i will test everything of you guys responses
  17. If you want a example of the document with no flicker. pm me, I have server where u can see the anti flicker.
  18. cool that's great!! i will tell you if i don't fix it.
    • Like Like x 1
  19. well NubeBuster method seems to be working but it's kinda slow at loading the new scores before it reloaded the scores every time i killed someone or taking money and stuff in 1 seconds and now it takes almost 8 seconds to add the new score because i changed it to }0, 200L); but the flashing thing now its not happening it's like rare it happends tho but not like before it takes time to happend again.
  20. Pm me, ill help you.