Scoreboard Flickering

Discussion in 'Plugin Development' started by tvtad202020, Jun 26, 2017.

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

    tvtad202020

    i made a scoreboard with time , so i need to update it every 20 seconds , and it flickering i don't know why , pls help <3.
    Code :
    Code:
      @EventHandler
      public void PlayerJoin(PlayerJoinEvent events) {
        final Player p = events.getPlayer();
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
        {
          public void run() {
            if (Main.this.times) {
              Main.this.getConfig().set("Seconds", Integer.valueOf(Main.this.getConfig().getInt("Seconds") + 1));
              Main.this.saveConfig();
              if (Main.this.getConfig().getInt("Seconds") >= 60) {
                Main.this.getConfig().set("Seconds", Integer.valueOf(0));
                Main.this.getConfig().set("Minutes", Integer.valueOf(Main.this.getConfig().getInt("Minutes") + 1));
                Main.this.saveConfig();
              }
            }
          }
        }
        , 0L, 20L);
    
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
          public void run() {
            Main.this.board = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
            Main.this.o = Main.this.board.registerNewObjective("test", "dummy");
            Main.this.o.setDisplayName("§bBlocksSG §4" + Main.this.time(0));
            Main.this.o.setDisplaySlot(DisplaySlot.SIDEBAR);
            Score s11 = Main.this.o.getScore("§cKills:");
            s11.setScore(11);
            Score s10 = Main.this.o.getScore(ChatColor.YELLOW + Main.this.getConfig().getString("Kills"));
            s10.setScore(10);
            Score s9 = Main.this.o.getScore(" ");
            s9.setScore(9);
            Score s8 = Main.this.o.getScore("§bRemaining:");
            s8.setScore(8);
            Score s7 = Main.this.o.getScore(ChatColor.YELLOW + Main.this.getConfig().getString("Remaining"));
            s7.setScore(7);
            Score s6 = Main.this.o.getScore("  ");
            s6.setScore(6);
            Score s5 = Main.this.o.getScore("§bSpectators:");
            s5.setScore(5);
            Score s4 = Main.this.o.getScore(ChatColor.YELLOW + Main.this.getConfig().getString("Spectators"));
            s4.setScore(4);
            Score s3 = Main.this.o.getScore("   ");
            s3.setScore(3);
            Score s2 = Main.this.o.getScore("§bServer:");
            s2.setScore(2);
            Score s1 = Main.this.o.getScore("§eSG" + ChatColor.YELLOW + Main.this.getConfig().getString("Server"));
            s1.setScore(1);
    
            p.setScoreboard(Main.this.board);
          }
        }
        , 0L, 9L);
      }
    ----------------------
    i don't want to set the players kill i just want to fix the flickering problem , thx <3.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @tvtad202020 Re-use the old scoreboard instead of making a new one every time.
     
  3. Offline

    tvtad202020

    @timtower okay can u write it please cuz im new at coding? <3
    So what should i change in the code
     
  4. Offline

    timtower Administrator Administrator Moderator

    @tvtad202020 I won't spoonfeed.
    Make 1 scoreboard in your onEnable and keep using that instead of your line with getNewScoreboard.
     
  5. Offline

    tvtad202020

    Okay what should i write on onEnable to get it ,.?
    @timtower

    @timtower cuz i need it to my server SG please

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 27, 2017
  6. Offline

    Zombie_Striker

    @tvtad202020
    1. If the player has a scoreboard, use that scoreboard instead of creating a new scoreboard.
    2. If not, that is when you should create it.
    3. After that, do not reset all the data. Instead, only update the variables that have changed.
    4. Do not set the player's scoreboard over and over again. It only needs to be set once if the player does not have a scoreboard.
     
  7. Offline

    tvtad202020

    @Zombie_Striker okay how can i do the first thing *
    1. If the player has a scoreboard, use that scoreboard instead of creating a new scoreboard

      also how can i change the only update variables ,, i need to update the time and kills only how can i make it?
     
  8. Offline

    Zombie_Striker

    @tvtad202020
    [EDIT] It seems you are storing a global scoreboard anyway (this.board). Instead of creating a new scoreboard every time, just check if that is not null. If it is not, you don't need to re-set that scoreboard (I.e, if board is not null, don't use the getNewScoreboad line)

    To do that, do the following:
    1. Figure out which variable changed, whether it be the 'remaining', the 'spectators', or the 'server'.
    2. When you do, figure out what 'score' it uses.
    3. For loop through all the scores for the scoreboard
    4. If the score equals the one from #2, remove it and add the new entry with that same score.
     
  9. Offline

    tvtad202020

    dude i can't understand what are you talking about , please can you edit the code and send it because i need it please :(*
    @Zombie_Striker
    can i talk to u on any talk program?
     
    Last edited: Jun 27, 2017
  10. Offline

    Zombie_Striker

    @tvtad202020
    1. No. All thread related topics need to stay on this thread.
    2. Only call this line if board is null.
    3. No, I will not spoonfeed. If I honestly needed to, that means that the issue is so complex not even words would let you understand what you need to do (which would mean the problem is so involved you shouldn't be writing this plugin at all) Instead, let me rephrase what you need to do.
      What this says is figure out if something changed (such as the amount of spectators or the amount of remaining players). If something did change, get the score for those entries (Base on your code above, if Remaining changed, you would need to use score 7, and if Spectators changed, it would be score 4) Once you figure out which score you are looking for, for loop through all the entries for the scoreboard (using Scoreboard#getEntries). If the score for that entry (use Scoreboard#getScore(...)) is equal to the one you are looking for, remove it (using Scoreboard#resetScores(....)) and then add a new score with the values you want (basically, calling one of the score lines above like S4 or S7).
     
  11. Offline

    tvtad202020

  12. Offline

    Zombie_Striker

    @tvtad202020
     
Thread Status:
Not open for further replies.

Share This Page