Solved Preventing Scoreboards from Flickering - Changing Objectives

Discussion in 'Plugin Development' started by Bionicrm, Feb 27, 2014.

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

    Bionicrm

    I'm creating a scoreboard and I need the scores to be text, not a number. So, I have an objective with different scores that have text containing the needed information. However, if I want to change the text, I have to remove the objective and create a new one with the updated text (well, I think I have to do this).

    So this all works and stuff, but when I test this on a different computer other than my own, the scoreboard appears to flash when it's updated (which happens every 2 seconds and on a player join/quit event).

    There's no point in posting code since I'm asking for ideas on what to do, and I'm not asking for the code itself.
     
  2. Offline

    calebbfmv

    Threads.
    -leaves-
    No but for real, Async and threading (done right) will stop this.
     
  3. Offline

    Bionicrm

    calebbfmv Well since we're talking about threading now, how would I achieve this (considering Async Bukkit threads cannot access the API)? Any ideas (not code)?
     
  4. Offline

    calebbfmv

    Bionicrm
    Erm, creating and managing your own thread to handle scoreboards.
     
  5. Offline

    Bionicrm

    calebbfmv I don't think this is enough information. I know that you can't access the API within an async thread.
     
  6. Offline

    calebbfmv

    Bionicrm
    You can't? I do not think so, I do it just fine.....
     
  7. Offline

    Bionicrm

  8. Offline

    calebbfmv

    Bionicrm
    I can't, without sending code. I know this works the exact way I run it, Async, on my own Thread. It is just fine. Bukkit doesn't want you to, but you can.
     
  9. Offline

    Bionicrm

    calebbfmv Then share your code. I originally said "not code" because I didn't just want a quick spoon-feed, but if I can't understand what you mean by you just saying it, then yes, I'll need to see some code. Thanks :)
     
  10. Offline

    calebbfmv

    Bionicrm
    When I get a chance, I will.
     
  11. Offline

    oscarshi1995

    Bionicrm did you ever figure this out? solutions? because I'm having the same issue xD
     
  12. Offline

    Bionicrm


    There's no direct solution. All you have to do is make sure that you only update the scoreboard when you absolutely need to. What I was doing was updating the scoreboard every few seconds, regardless of if there was a change. The flash is more noticeable on higher latencies.

    Edit: Have a look at my latest post.
     
    ZeusAllMighty11 likes this.
  13. Offline

    ZeusAllMighty11

    Bionicrm

    I developed some scoreboard plugins and I never experienced the issue, but the receivers of the plugin did.. I couldn't fix it because I couldn't see it..

    No solution AFAIK, aside from what you've said.
     
  14. Offline

    fireblast709

    Bionicrm setDisplayName() instead of setting new objectives perhaps
     
  15. Offline

    Bionicrm

    ZeusAllMighty11 likes this.
  16. Offline

    oscarshi1995

    Thats the thing, I did provide a Objective with everything already in it but it STILL blinks lol

    Code:java
    1. private void sendUpdate(Player player, boolean complete) {
    2. final Objective oldobjective = player.getScoreboard().getObjective(DisplaySlot.SIDEBAR);
    3.  
    4. final Objective objective = player.getScoreboard().registerNewObjective(UUID.randomUUID().toString().substring(0,16), DUMMY_CRITERIA);
    5.  
    6. final Iterator<Map.Entry<String, String>> iter = Settings.getItems();
    7. double a = 0;
    8. while (iter.hasNext()) {
    9. final Map.Entry<String, String> entry = iter.next();
    10. final String title = entry.getKey();
    11. final String variable = entry.getValue();
    12. try {
    13. String old = "";
    14. for(String i : objective.getScoreboard().getEntries()){
    15. if(i.contains(ChatColor.translateAlternateColorCodes('&', title))) old = i;
    16. }
    17. final double score = replaceManager.getScore(player, variable);
    18. sendScore(objective, title, score, complete,++a, old);
    19. } catch (UnknownVariableException ex) {
    20. //Remove the variable becaue we can't replace it
    21. iter.remove();
    22.  
    23. plugin.getLogger().info(Lang.get("unknownVariable", variable));
    24. plugin.getLogger().log(Level.FINE, null, ex);
    25. }
    26. }
    27. objective.setDisplayName(Settings.getTitle());
    28. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    29. oldobjective.unregister();
    30. }


    Current code I am using, It still flickers...

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

    oscarshi1995

  18. Offline

    oscarshi1995

  19. Offline

    TheMrGong

  20. Offline

    oscarshi1995

    Do I HAVE to fiddle with packets with this? or does the bukkit have some api for this?
     
  21. Offline

    mamifsidtect

    Oh goodness! I have just the right thing. I'm using it right now in my game. I just made a method to update individual scoreboards of the players in-game, and then I also made it so I can loop through an arraylist of the playerdata and update ALL player scoreboards using the same method
     
  22. Offline

    AronTheGamer

    You don't need to remove the objective, only the score of the 'Player' with the name you use as text value
     
  23. Offline

    oscarshi1995

    AronTheGamer Ive tried that as well, but you can see on the client the process of removing the old name and putting in the new name like at some times you would have a extra entry for a tick and other times 1 less for a tick
     
  24. Offline

    oscarshi1995

    Can I see what you did?
     
  25. Offline

    mamifsidtect

    oscarshi1995 When I get some time on the computer I'll give you some code, it should work but mind you, it will be untested, but you will get the gist of it
     
  26. Offline

    negative_codezZ

    I am having this issue too, please?
     
    KingFaris11 likes this.
  27. Offline

    mamifsidtect

    Sorry about the long wait, computer crashed and I had to get a new one, here is some code that I used to update the scoreboards:

    Code:java
    1. public void updateScoreboard(Player p) {
    2.  
    3. SimpleScoreboard ss = new SimpleScoreboard(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Golden"
    4. + ChatColor.YELLOW + "Gun" + ChatColor.DARK_GRAY + "]");
    5. ss.add("===================");
    6. ss.blankLine();
    7.  
    8. ss.add(ChatColor.YELLOW + "Current Map:");
    9. ss.add("" + mapName);
    10. ss.blankLine();
    11.  
    12. ss.add(ChatColor.YELLOW + "Current Players:");
    13. ss.add("" + currentPlayers);
    14. ss.blankLine();
    15.  
    16. ss.add(ChatColor.YELLOW + "Kills:");
    17. ss.add("" + GameListener.getInstance().getPlayerKillsMap().get(p.getName()));
    18. ss.blankLine();
    19.  
    20. ss.add(ChatColor.YELLOW + "Phase:");
    21. ss.add("Pre-Alpha");
    22. ss.blankLine();
    23.  
    24. ss.add("===================");
    25. ss.build();
    26.  
    27. ss.send(p);
    28. }


    And this is the link to SimpleScoreboard.java, which you WILL need to get the above code working: link

    Btw, that code is made by someone else on the forums, and that person is @RainoBoy97
     
Thread Status:
Not open for further replies.

Share This Page