Help with Scoreboard Flickering

Discussion in 'Plugin Development' started by ferrago, Mar 28, 2015.

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

    ferrago

    Hey, so i am using a scoreboard to show messages the typical way where each line contains the information and the score setting for each line descends from 15 to 1. I am having the issue of when I update the scoreboard it flickers. Is there a way to get around this.

    The current ways i have tried updating are as follows
    1) Unregister the objective and create a new one in the same spot. (Still flickered)
    2) Reset all scores currently in the scoreboard and then add the score.
    3) Each time I add a new score I remove an old one (Since I always update all scores, and always have the same number of scores, this in theory should work well) There is still a noticeable flicker.

    By flicker I mean that for a split second the scoreboard changes in some way noticeable enough that it looks as if it flickers.
     
  2. Offline

    Konato_K

    @ferrago To stop flickering you need to:
    - Reset the score you want to remove
    - Add the new score you want to show

    The next things will cause flickering
    - Setting the scoreboard again
    - Creating a new objective
     
  3. Offline

    ferrago

    @Konato_K
    I am doing that. It still is flickering. I was able to tell that it always seems the flicker is caused by the last score on the scoreboard being removed and added back.

    Here is a sampling of the code.

    This is the update method being called to update (in a task happening every 1 second)
    Code:
            int i = 14; // start at 14 because we don't want to remove the seperator.
            for (String skill : hero.getCooldowns().keySet()) {
                addMessage(ChatColor.WHITE + "" + skill + ": " + ChatColor.GREEN + TextUtil.formatTimeInMillis(hero.getCooldown(skill) - System.currentTimeMillis()), i--);
            }
            for (int position : messageMap.keySet()) {
                if (messageMap.get(position).contains("00:00:00")) {
                    removeMessage(position);
                }
            }
    This is the addMessage method
    Code:
        public void addMessage(String message, int position) {
            //If the position is greater than our max position.
            if (position > 15) {
                return;
            }
            //We want to remove the old message at this position.
            if (messageMap.containsKey(position)) {
                board.resetScores(messageMap.remove(position)); //This will remove the old entry and remove the score.
            }
            objective.getScore(message).setScore(position); //This will add the new message to the board at this position.
            messageMap.put(position, message); //Store this message for later
        }
     
  4. Offline

    xTigerRebornx

  5. Offline

    ferrago

    @xTigerRebornx
    Thank you for this method, however it is using the deprecated OfflinePlayer method, which is required for your method as you update the fake player's prefix/suffix to modify the scoreline. I have learned when you have multiple people with multiple scoreboards that Bukkit.getOfflinePlayer() causes way too much lag. It is slow and inefficient and way to costly on larger servers. Thanks for the tip though it is interesting. I have noticed some flickering on larger servers such as Hypixel, so maybe this is something you just have to live with. I am attempting to write a fully packet operated scoreboard system instead of maintaining physical scoreboard objects.
     
  6. Offline

    xTigerRebornx

  7. Offline

    ferrago

    @xTigerRebornx My information was a bit dated, I will run this on one of the main servers I manage and see how it impacts performance. Thanks for the information!
     
Thread Status:
Not open for further replies.

Share This Page